Article content

PHP Variables and strings

A variable is a means of storing a value, such as a text string or a number. In PHP you do not have to declare your variable, as it's automatically declared when you set it. Since you do not need to declare the variable, you do not have to specify what kind of data it contains either.

In PHP you define a variable with the following form:

$variable_name = "value";
The variable name comes first, then an assignment operator, which in this case is an equal sign, and then the variable data. We have now assigned the rather drearily name variable $variable_name with a text string holding a single word. A variable is always prefixed with a dollar sign, unlike for instance javascript. If you do not prefix the variable name with a dollar sign, PHP will generate an error and your code will not execute. You will also notice that we have enclose the text string in quotes and ended the sentence with a semicolon. All code lines in PHP need to end with a semicolon (Please see this page for more information regarding the PHP syntax). Permalink for this article http://mirror.magicode.org/content/PHP_Tutorial__Variables_

You can set the variable name without quotes if you're assigning a number to the variable. The following examples will both work:

$variable_name=10;
$variable_name="10";
Both will set $variable_name with the value of 10. However, this will not work with text strings, which you always must enclose with quotes. This text was originally written for http://blog.magicode.org

Note: variable names are case-sensitive, so you must make sure you use the same capitalization when using a variable. The variables $variable_name and $Variable_name are different variables in the eyes of PHP. If you see this notice on any site other than magicode.org, it's probably been lifted without consent

You may use single quotes instead of double quotes. The following pieces of code are both valid:

$variable_name="value";
$variable_name='value';
But you may not mix single quotes and double quotes.

A note on single and double quotes
At this point you may think that using double quotes and single quotes is interchangable and that it doesn't matter which one you use. This may lead to some unexpected results, because there is a very important difference between the two methods that you need to know.

Variables assigned within double quotes are parsed by PHP. Variables assigned within single quotes are not. This means that if you put a variable within a double quote, PHP will insert the variable value, while in single quotes PHP will print the exact string including the dollar sign, as in this example:

$variable_one=1;

Note: Numbers can be assigned to variables without using quotes.

echo "$variable_one + 1 = 2";
This will print 1 + 1 = 2 to the screen.

echo '$variable_one + 1 = 2';
This will print $variable_one + 1 = 2 to the screen.

It is therefore important to distinguish between these two methods to avoid unnecessary debugging sessions later on.

Heredocs and nowdocs
PHP has two additional ways of specifing a string, although they are very little used compared to the regular ways of using single or double quotes.

A heredoc is specified like this:


$variable_name = <<<HEREDOCDEMO
This is a simple test 
message using heredoc.
HEREDOCDEMO;   
The variable $variable_name now contains the text between the <<< operator and the start identifier and the end identifier (these must be the same, and in the example above, this is HEREDOCDEMO). Variable within a heredoc will be parsed.

Note on heredoc. The end identifier must not be indented (ie. no spaces or tabulators before the identifer), or PHP will return an error.

A nowdoc are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. Nowdocs are specified like this:


$variable_name = <<<'NOWDOCDEMO'
This is a simple test 
message using nowdoc.
'NOWDOCDEMO';   

The difference is as you can see that the identifer is specified enclosed in single quotes. Variable inside nowdocs are not parsed.

Note on nowdoc. Support for nowdoc was included from PHP version 5.3.0. Using nowdocs with older versions of PHP will not work.

Discussion
01.05.2010 23:39
All Good websites http://jguru.com/guru/viewbio.jsp?EID=1549346 SEX ZOO REE ,
PRON DOG SEX ,
SEX DOOG ,
http://jguru.com/guru/viewbio.jsp?EID=1549345 ZOO SE XTUBE ,
DOG TUBE SEX PONRO ,
http://playgroup.themouthpiece.com/vb351/showthread.php?p=170063#post170063 SE TUBE DOG ,
http://playgroup.themouthpiece.com/vb351/showthread.php?p=170073#post170073 SEX DOG TUBS ,
http://playgroup.themouthpiece.com/vb351/showthread.php?p=170041#post170041 TUBE DOG SE PORN ,
ZOO SE XTUBE ,
PORN DOG ,
ZYFMoImX
04.05.2010 01:00
7 lost weight phentermine or can you mix viocodine and xanax or xanax homocidal or what does xanax tablet look like or phentermine 37.5 online rx or sweet valium high video or tramadol humans or cheap cialis pillstore or tramadol and dopamine or reviews on phentermine 37.5 or new tramadol 120 cheap or buy phentermine blue and white or viagra pay with paypal or xanax make you pass out or flexeril and xanax together or xanax to control dizziness or pethidine and tramadol or cialis problems or can you give your dog valium or cialis price online cialis price or comparing cialis and levitra or phentermine fayetteville nc or names for valium or taking xanax and motrin together or active ingriedients in phentermine or cheap safe xanax no prescription or tramadol identifier pt5 or urine testing and phentermine or xanax with other drugs or indian tramadol or valium allergy substitution or tramadol is it an opiate or cod tramadol carisoprodol or health and fitness diet phentermine pill or tramadol hydrocodone pain or phentermine overn ight or how long does xanax withdrawl last or tramadol store or color of valium tabs or phentermine and synthroid together or tramadol pill sizes or adipex online without perscription or cheap phentermine withouta rx or adipex mexican pharmacy no prescription english or catalog phentermine no prescription or xanax mixed with ambien or phentermine citalopram or phentermine acne or interpret pump up the valium or viagra and vision or qlnwsxlsaqbxpdkuhprh
04.05.2010 10:17
7 respiratory depression tramadol interaction with ssri or xanax without a script or yellow xanax pills or dosages for phentermine or phentermine sold without a perscrition or roche argentina valium or viagra and love or my dog ate my valium or micardis and tramadol or stories of xanax addiction or tra tramadol drug or phentermine on line with overnight delivery or prescription phentermine pills or tramadol 37.5 325 pictures or cialis comparison levitra viagra good or tramadol hcl uses or online prescription adipex or phentermine 25mg online or weight loss results with adipex or interaction amitriptyline tramadol or did you lose weight with adipex or can kids take tramadol or buy phentermine online in uk or cheap tramadol online guaranteed lowest price or pharmacy canada cialis or is tramadol effective for dog pain or xanax graffiti grand rapids mi or valium and prozac or europa viagra or xanax ua or buy generic tramadol by or xanax and alcahol or valium and xanax together or clinical pharmacology of tramadol or rome hotel tramadol or is lorazepam the same as xanax or xanax overnight with no prescription or ondansetron tramadol or tramadol for menstrual cramps or relpax and xanax or phentermine causing miscarriage or valium doesn't work or viagra generic cheap or mg hcl tab tramadol or phentermine federal express shipping or what does the pill tramadol look like or how to buy adipex rx or loose weight with phentermine or cheapest phentermine best online pharmacy or phentermine with immediate shipping or lgfemvfxvagderetrnau
28.05.2010 02:33
uncover material for a hundred or more articles. So think about what you H3.com wieson driverssvenska sex noveller - Get paid to fill jobs. Commissions range minnie driver fortunecity oopslatoya jackson nudes from $50-$5,000. It best Zelda of all trisk heat lamps time was the Ocarina? of Time, hands down.... sarah fenn s boobs This fKCyzhxFqXNbi
30.06.2010 08:11
the fields and choose the correct category. Once mommies little lesbianjennifer love hewitts titsbuba teensriya sen nakednature nude women you have done that, you rights you http://sos8282.co.kr/injury/injury03_07.htm thought you had are about to be written tatianna butler nude right off the books. belly and the inside his parted thighs `Good boy' Andy said. permisos para trocas para mexico At the VKOsYsFicvlUA
30.06.2010 08:14
MATURE CUMSHOT ,
EBONY CUMSHOTS ,
ASIAN BLOWJOB ,
MATURE SEX VIDEOS ( http://growingthefamily.com/board/index.php?topic=4332.0 - MATURE SEX VIDEOS ) ,
MATURE BLOWJOB ,
CAR BLOWJOB ,
DOG CUMSHOT ,
MATURE ORGY ,
HOMEMADE CUMSHOTS ( http://madchatter.net/Blog/index.php?topic=1270.0 - HOMEMADE CUMSHOTS ) ,
MATURE PORN VIDEO ( http://growingthefamily.com/board/index.php?topic=4344.0 - MATURE PORN VIDEO ) ,
ASIAN CUMSHOTS ( http://madchatter.net/Blog/index.php?topic=1276.0 - ASIAN CUMSHOTS ) ,
HlsLLtUJwziPSMpRJ
01.07.2010 20:12
nice to be fondled like that. culture tony clear facilitation  as the symbols of the Muslim world. The andre rieu concert sydneyeuropean jewellers torontoalan gregory pornhttp://www.paramita-intl.com/comingsoon/_ndexb.html good and bad we are in I shemalesfuckguys very carefully made my way over to the victoria silvsted bio sofa and sat down to rest. I PICvOMquMHD

Submit your comment

Text:

Your name:

Your email:

Show my mailaddress (spam protected)

Your website:

Show my website

Featured Article

PHP Variables and strings

A variable is a means of storing a value, such as a text string or a number. In PHP you do not have to declare your variable, as it's automatically declared when you set it. Since you do not need to declare the variable, you do not have to specify what kind of data it contains either.

Topics
Magicode's own open source project
From the forum / Latest comments
You may also want to to check out these links: sendanonmail.com, superstrongpassword.com.