Re: Single Quotes vs Double Quotes

From: Date: Tue, 09 Sep 2003 04:23:00 +0000
Subject: Re: Single Quotes vs Double Quotes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-162035@lists.php.net to get a copy of this message
--- micro brew <microbrewclub@yahoo.com> wrote: > Could somebody please explain to me the difference > between single quotes and double quotes in PHP. Strings within single quotes are not evaluated. String within double quotes are. Try this example: <? $foo = 'bar'; echo '$foo'; echo "$foo"; echo $foo; echo 'bar'; echo "bar"; ?> If there is nothing to be evaluated (such as a variable), as is the case in the last two examples, you will notice no difference. Also, because single quotes within a string must be escaped when single quotes are the delimiter, and vice versa, it is sometimes convenient to choose based on that alone. For example: $sql = "select foo from bar where blah='whatever'"; instead of: $sql = 'select foo from bar where blah=\'whatever\''; or: echo '<a href="http://www.php.net/">PHP</a>'; instead of: echo "<a href=\"http://www.php.net/\">PHP</a>"; Hope that helps. Chris ===== Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/

« previous php.general (#162035) next »