Lesson #4

PHP String Escape Sequences

echo "Hello, World!\nThis is a String!";
/* prints-
Hello, World!
This is a String!
*/

In PHP, sometimes special characters must be escaped in order to include them in a string. Escape sequences start with a backslash character (\).

There are a variety of escape sequences that can be used to accomplish different tasks. For example, to include a new line within a string, the sequence \n can be used. To include double quotation marks, the sequence \” can be used. Similarly, to include single quotes, the sequence \’ can be used.