Part 4: Escape

Activity 3 Homepage

Example Using Escape Slash

It's a beautiful day!



Example NOT Using Escape Slash

It's a beautiful day!



Escape Slash Explanation

In the first example, the escape slash (\) is used before the single quote to prevent it from terminating the string early.
This allows the single quote to be treated as part of the string. In the second example, without the escape slash, the single quote would cause a syntax error because PHP would interpret it as the end of the string. Therefore, requiring the use of double quotations in the second example to avoid a syntax error.