Advertisement
Google Ad Slot: content-top
PHP Escape Characters
Escape characters are used to represent characters that are difficult or impossible to type directly in a string, or to insert special characters within a string. These escape characters are typically represented with a backslash (\) followed by a character or a sequence.
Common Escape Characters in PHP
Here’s a list of commonly used escape sequences in PHP:
Escape Sequence |
Description |
Example |
|---|---|---|
\' |
To include single quotes inside a string |
echo 'It\'s a sunny day!' |
\" |
To include double quotes inside a string |
echo "She said, \"Hello!\""; |
\\ |
To include a literal backslash ( |
echo "C:\\Program Files\\PHP"; |
\n |
To insert newline characters ( |
echo "Hello\nWorld!"; |
\r |
Moves the cursor to the start of the line |
echo "Hello World\rPHP"; |
\t |
It inserts a horizontal tab space |
echo "Name\tAge\nJohn\t25"; |
\f |
Form feed(Rarely used) |
"Text\fEnd" |
\xXX |
Hexadecimal character (XX is a two-digit hex number) |
echo "\x48\x65\x6c\x6c\x6f"; |
\u{XXXX} |
Unicode escape (for characters above 255) |
echo "Hello \u{1F600}";
|