PHP Quotes and Apostrophes – the Difference

by Carey on October 19, 2010

Post image for PHP Quotes and Apostrophes – the Difference
  • Share
  • CevherShare
  • Share

Many people seem to be confused with the use of quotes and apostrophes when coding in PHP.

Using apostrophes is the “lightweight” way. Use these when you just want to create a string:
$var = 'This is just plain old text.';Using quotes will provide you with a bit more functionality and in turn is slightly more expensive in execution:

 # Use \n to add a new line
$var = "This is the first line\nThis is the second line";
 # Include the value of a variable
$var = 'bones';
echo "Don't rattle my $var";

Please note also that PHP will evaluate any text in quotes – it is therefore more efficient to use apostrophes by default and use quotes only when you need them.

Leave a Comment

Previous post:

Next post: