PHP characters that need to be escaped

In writing PHP code, several characters need to be “escaped” for the code to run properly. If not, the browser will be blank or show errors.

The following characters have to be escaped, which means you write a backslash ( \ ) in front of it.

For example: \- (the hiphen) or \. (the dot).

Other special characters are:

” ^ [ $ ( ) | * + ? { \ ” .

A quick example:

[sourcecode language=’php’]


2 Comments on “PHP characters that need to be escaped”

  1. In the example, the ‘ is escaped because otherwise $str would equal ‘It’ and then there would be a bunch of junk code before the next ‘ which would start a new in-code string which would upset the precarious balance of quotations.

Leave a Reply

Your email address will not be published. Required fields are marked *