A string of characters—a string—is probably the most commonly used data type when developing scripts, and PHP provides a large library of string functions to help transform, manipulate, and otherwise manage strings. We introduced PHP strings earlier, in Section 2.1.1. Here, we examine string literals in more detail and describe some of the useful string functions PHP provides.
As already shown in previous examples,
enclosing characters in single quotes or double quotes can create a
string literal. Single-quoted strings are the simplest form of string
literal; double-quoted strings are parsed to substitute variable
names with the variable values and allow
characters to be encoded using escape
sequences. Single-quoted strings don’t support all
the escape sequences, only
\' to include a single
\\ to include a backslash.
newline, and carriage-return characters can be included in a
double-quoted string using the escape sequences
\r, respectively. To include a backslash, a dollar
sign, or a double quote in a double-quoted string, use the escape
Other control characters and characters with the most significant bit
set can be included using escaped octal or hexadecimal sequences. For
example, to include the umlauted character ö, the octal
\366 or the hexadecimal sequence
\xf6 are used:
//Print a string that includes a lowercase //o with the umlaut mark echo "See you at the G\xf6teborg Film Festival"; ...