PHP Escape Slash

Example NOT using escape slash

He said: "Hello Sahil"

Example USING escape slash

He said: "Hello Sahil" and welcomed me.

Explanation

The escape slash (backslash \) tells PHP to treat the next character as normal text instead of ending the string. In these examples, the backslash allows quotation marks to appear inside an echo statement without confusing PHP. Without escaping, the quote could end the string early and cause an error, so escaping keeps the output correct.

Back to index