The PHP Escape Slash

Back to index

Example 1: USING the escape slash

The "large coffee" costs $5.

Example 2: NOT using the escape slash

The 'large coffee' costs 5.

Explanation

The escape slash is used when I need to print a special character inside a string. For example, I can use a backslash before double quotes so PHP does not think the string has ended. It helps PHP understand exactly what I want to display on the page. The \$ in Example 1 prints the dollar sign before the price. The \" allows the double quotes to appear inside the string. Example 2 could not show the double quotes in the same way without using the escape slash.