Well basically you would use double quotes whenever you want the data/text
in between the quotes to be parsed, so for instance:

$name = 'Rick';
echo "My name is $name";     // output = My name is Rick
echo 'My name is $name';     // output = My name is $name
echo "My name is \"$name\""; // output = My name is "Rick"
echo 'My name is "$name"';   // output = My name is "$name"
echo "My name is '$name'";   // output = My name is 'Rick'

Whenever a string does not need to be parsed go ahead and use the single
quote, whenever it needs to be parsed use double quotes, but remember
whichever quote you decide to use, if you want to use the same quote inside
your string you're going to have to escape the quote inside your string
using the forward slash.

I try to make sure all my html has double quotes so if I echo just plain
html I use the single quotes that way I do not have to escape my double
quotes... 
example:
echo '<img src="hello.gif">';
instead of
echo "<img src=\"hello.gif\">";

I hope all of that made sense! :)

Rick
 

> I was looking through some PHP books and scripts on the web and I have
> noticed different syntax for inputting and outputting data.
> 
> For example the book PHP essentials used a format of slash and quotations:
> 
> $sql = "INSERT INTO USER_TRACK VALUES (\"$user_id\", "$sel
> 
> echo "$user_id";
> 
> 
> Another script which was used for discussion group, , used the following
> format:
> 
> $sql = "INSERT INTO discussion_board ('$name', '$subject'
> 
> echo $name;
> 
> I was wondering what is the difference between using single quotes and
> double quotes with slashes and the difference between using the
> "echo" command with or without the quotation around the variable?
> 
> Thanks.
> 
> Peter
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to