PHP 5.3 has four kinds of literal strings.
- single quoted
- There is neither variable nor special character interpolation 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.
Backslashes that preceede any other character besides backslash or single quote are literal.
- double quoted
- Backslash notation for \n,
\r,
\t,
\v,
\f,
\\,
\$,
\".
- Octal notation for chars: \[0-7]{1,3} Hex notation for chars: \x[0-9A-Fa-f]{1,2}
- 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.