Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : Web Architecture : Education - Tutorials
Writing efficient PHP
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
3. Tweaking PHP code
  


Quoting strings page 3 of 11


The PHP language supports two ways of quoting strings -- with double quotes or single quotes. Strings in are single quotes are not expanded but used as is. Often this is sufficient. See "Using Strings," listed in Resources, for more information on the different uses of strings in PHP.

When using character strings don't need to be expanded, such as those without any variable references or escaped characters, use single quotes instead of double quotes. Because strings within single quotes are not parsed, they are executed more quickly than strings inside double quotes that must be parsed first.

Note that this performance enhancement may seem unnatural to C, C++ or Java developers who typically use double quotes for strings and single quotes to indicate a character. Since I work mostly in C++ and Java, I still find myself using double quotes for strings when writing PHP code. It's a hard habit to kick, but kicking it can buy you a little better performance from your PHP applications.


Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact