PHP Quotes and Apostrophes – the Difference

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:

{code type=php} # Use \n to add a new line
$var = “This is the first line\nThis is the second line”;{/code} {code type=php} # Include the value of a variable
$var = ‘bones’;
echo “Don’t rattle my $var”;{/code}

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 Reply

Your email address will not be published.

More Posts

How to use PHP Type Declarations

PHP has developed into a more strictly typed language in recent years. Type Declarations help with that and are a fairly new addition to PHP,


If you have come to JavaScript from a background in Java or C, then you will like the variation on the for loop. It is

Context Object Manipulation

One of the key concepts of JavaScript is the keyword this, which signifies the JavaScript context object. If you write an inner function, you can access

Polymorphic Functions

It is possible to define multiple functions with the same name in JavaScript, and the last one of those that you define will be the