PHP Escape Characters

When you need to include characters in a string that are otherwise illegal, you can use an escape character.

Tutorials dojo strip

An escape character is a backslash \ followed by the character you wish to include.

Example: Including Double Quotes in a String

Consider a situation where you want to include double quotes inside a string that is itself surrounded by double quotes:

PHP

Common Escape Characters

Here are some common escape characters used in PHP:

CodeResult
\'Single Quote
\"Double Quote
\$PHP variables
\nNew Line
\rCarriage Return
\tTab
\fForm Feed
\oooOctal value
\xhhHex value

Basic Example

To include a double quote in a string:

PHP

Single Quotes

To include a single quote in a string:

PHP

Tutorials dojo strip