PHP: The Difference between Single and Double Quotation Marks

PHPThis I didn’t actually know until just a little while ago.

Now I know \n means new line, \r means carriage return and \t means tab, but what I couldn’t figure out is why I couldn’t get PHP to spit them out correctly in my PHP echo statements. And I was like using

and everything! ;)

The problem?

Well it turns out I didn’t know that there actually is a pretty big difference between using single and double quotation marks to denote strings in PHP! And apparently this is a pretty big issue because most self-taught guys (like myself) really kind of gloss over this point in the basics.

Using single quotes essentially tells PHP that this is a string, use it as a string. Double quotes on the other hand tells PHP to parse the string, look for possible variable matches and escaping characters (like
for example) and then obviously substitute/operate on them as required.

So needless to say, using single quotes (with concatenation in of variables if required) in your script is far quicker and more efficient than using double quotes, which really should on be used when you DO actually need to make use of escaped characters and the like.

Seriously. You learn something new every day.

You might also enjoy:

About Craig Lotter

Craig Lotter is an established web developer and application programmer, with strong creative urges (which keep bursting out at the most inopportune moments) and a seemingly insatiable need to love all things animated. Living in the beautiful coastal town of Gordon's Bay in South Africa, he games, develops, takes in animated fare, trains under the Funakoshi karate style and for the most part, simply enjoys life with his amazing wife and daughter. Oh, and he draws ever now and then too.
This entry was posted in Technology & Code, Tutorials. Bookmark the permalink.
    blog comments powered by Disqus