Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Chris Shiflett's Blog:
Quoting PHP Strings
Aug 26, 2005 @ 10:54:18

In Chris Shiflett's new blog post today, he talks about the quoting of PHP strings and a few of the "gotchas" involved.

PHP developers generally understand the difference between using single quotes versus double quotes to enclose a string. If you need stuff to be interpreted, you use double quotes. If you need to indicate a literal string, you use single quotes.

Therefore, within a string enclosed with single quotes, PHP needs to allow both single quotes and backslashes to be escaped. I'm not sure if this is explained very clearly in the manual.

He gives examples of double-quoted strings with variables, double-quoted strings with slashes, single-quoted strings with slashes and a few more - giving the reasoning for why they output what they do. He's looking to alleviate some of the confusion that might not be helped by the strings section of the manual...

tagged:

Link:


Trending Topics: