PHP Escape Slash Examples

Example Using the Escape Slash

She said, "PHP is fun!"

The code uses: \" inside a double-quoted PHP string.

Example NOT Using the Escape Slash

She said, "PHP is fun!"

This example uses single quotes around the PHP string, so the double quotes inside do not need an escape slash.

Explanation

The escape slash, or backslash, tells PHP to treat the next character as part of the text instead of treating it as PHP syntax. In the first example, the backslashes allow double quotation marks to appear inside a double-quoted string. In the second example, single quotes surround the string, so the double quotation marks can be written normally.

Back to Activity 3