Strings
- Unicode is not natively supported.
- There are no practical limits on the size
of a string.
- Characters within strings may be
accessed by specifying the
zero-based offset of the desired character after the string in
curly braces,
{}.
- For backwards compatibility, square
brackets,
[], can be used
to access characters; this syntax has been deprecated as of PHP 4.
Functions
Double-quote strings
- Variables in the string will be expanded.
Backslash escapes
\" : Double quote
\\ : Backslash
\n : Linefeed
\r : Carriage return
\t : Tab
\$ : Dollar sign
\x[0-9A-Fa-f]{1,2} : Character value in hexadecimal.
\[0-7]{1,3} : Character value in octal.
- The backslash is treated as a regular
character if it
precedes any character other than the above.
Single-quote strings
- Variables in the string will not be
expanded.
Backslash escapes
\' : Single quote
\\ : Backslash
- The backslash is treated as a regular
character if it
precedes any character other than the above.
- To add newlines, the string literal
itself must contain
actual newlines (
\n will not be expanded).
echo 'This is how to embed
a newline in a single-quote string.';
Heredoc text
<<<IDENTIFIER
...
IDENTIFIER[;]
- Heredoc text behaves like a double-quote
string.
- Variables in the heredoc text will be
expanded.
- The backslash escapes for double-quote
strings can be used.
- Backslash escapes are not needed for
quote characters.
- The closing identifier must begin on the
first column of a
line.
- An optional semicolon can be placed
immediately after the
closing identifier.
- The first character before the closing
identifier must be a
newline as defined by the operating system (
\r on
Macintosh, for
example).
- When a text file is FTP'd in ASCII mode,
the FTP server will
know what kind of line ends to put in (and will do so).
echo <<<MYTEXT
This is some text
that will be displayed.
MYTEXT
echo <<<MORE_INFO
The value of $var1 is $var1
MORE_INFO;