CancelImage Upload

How to add quotes to symbols that have meaning within Regular Expressions in PHP

Every asked yourself whether or not a symbol within a regular expression required a backslash, in order for the syntax to work? After all, there are quite a few symbols to keep track of in regards to regular expressions. Especially to programming newbies distinguishing between the two can be a daunting task.

Here is a great way of finding out. By using the following function you will be able to distinguish between the symbols that have a meaning within regular expressions, and those that do not.

Those symbols that do have a meaning will be returned with a backslash in front of them. Here is an example using multiple symbols that do happen to have a meaning within regular expressions:


$string = ".\|: =!*?^$[](){}<>";

echo preg_quote($string);


Want to leave a comment?

No problem. Just enter your email and password below.

register | home | reminder

myDesignTool Networking •