The PHP Function Preg_Quote
The PHP language offers a set of functions to work with regular expressions, also known as regex. These are extremely useful in a wide variety of applications for text manipulation and search. One of the more powerful and widely used is the preg_ function family which provides powerful pattern matching capabilities.
The php function preg_quote is an important function when working with these functions. It adds a backslash in front of characters that have special meaning in regular expression syntax so that they can be searched for without the special meaning. This is particularly useful when you are dealing with run-time input and the string may contain special characters like
Essentially preg_quote() takes the string str and puts a backslash in front of any character that can be interpreted as part of regular expression syntax (or metacharacter, such as
It can also be used to quote characters that might be interpreted as an operator in a pattern. For example, the expression '2