...

View Full Version : php single quote and double quote



o0O0o.o0O0o
01-03-2008, 11:21 PM
hi friends ,

I am confused with one thing .
i have seen php scripts where eg.


$var1 = "bfd fd fd fdfdf $var nnn");

$var2 = 'fdf fdfd fdfd $var bf f fd';

$var3 = "fdf fdfd fdfd".$var."fdfdfd fdfs";

Now all these are working , but i have read somewhere that if we want to inser the variable value we have to use inside single quotes not double quotes

Can anyone provide me the description

CFMaBiSmAd
01-03-2008, 11:25 PM
Number 2 does not parse the variable and replace it with its contents.

As always, the answer to basic php questions are found in the manual - http://php.net/string

JohnDubya
01-04-2008, 05:30 PM
hi friends ,

I am confused with one thing .
i have seen php scripts where eg.


$var1 = "bfd fd fd fdfdf $var nnn");

$var2 = 'fdf fdfd fdfd $var bf f fd';

$var3 = "fdf fdfd fdfd".$var."fdfdfd fdfs";

Now all these are working , but i have read somewhere that if we want to inser the variable value we have to use inside single quotes not double quotes

Can anyone provide me the description

Definitely always do read the PHP manual. Pretty much any answer you need is in there somewhere...it's just difficult to find sometimes.

As for your question, if you use double quotes, any variables will be parsed (the value will be replaced) within the double quotes.


$first_name = 'John';
echo "Hello, Mr. $first_name! How are you?";
//This will echo: Hello, Mr. John! How are you?

If you use single quotes, you have to stop the single quote and use what's called "concatenation" (which is just a . ) Like so:


$first_name = 'John';
echo 'Hello, Mr. $first_name! How are you?';
//This will incorrectly echo: Hello, Mr. $first_name! How are you?

echo 'Hello, Mr. ' . $first_name . '! How are you?';
//This uses concatentation (a .) to glue the content together.
//This will echo: Hello, Mr. John! How are you?

felgall
01-04-2008, 06:47 PM
Both variables and escape characters are parsed when between "

The only thing parsed within ' is the one escape character \' - everything else will appear exactly as typed.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum