PHP 5.3 has four kinds of literal strings.

single quoted

Neither variable nor backslash interpolation, besides \' and \\ is done within single quotes. Single quotes need to be escaped with a backslash in order to be not taken for the delimiter. A backslash escapes a following backslash. A literal backslash needs to be escaped at end of string, as otherwise the delimiting single quote would be recognised as a literal single quote. In contrast to Perl 5, backslashes that preceede any other character are literal.

double quoted

The escape sequences \n, \r, \t, \v, \f, \\, \$, \" are recognised.

Charactes can alse be written in octal notation, \[0-7]{1,3}, and hexadecimal notation, \x[0-9A-Fa-f]{1,2}. The octal notation allows to specify values greater 256. In theses cases the value is taken as mod 256.

heredoc

   $param = 'dummy';
   $example = <<<EXAMPLE
   Variables are interpolated.
   $param
   EXAMPLE
Double quotes are literal. The backslashes before a double quote are literal. Unlike in Perl 5, the newline before the delimiter is not part of the string.

nowdoc

A heredoc with single quotes.

   $param = 'dummy';
   $example = <<<'EXAMPLE'
   Variables are not interpolated.
   $param
   EXAMPLE
Single quotes are literal. Backslashes are literal. Unlike in Perl 5, the newline before the delimiter is not part of the string.


parrot