preg_quote
string preg_quote(string input, [string delimiter])
input | String to escape |
delimiter | Optional delimiter character to escape |
Escapes all regular expression metacharacters in the input string.
Returns:
String with regular expression metacharacters escaped
Description:
Sometimes it’s necessary to have arbitrarily dynamic strings as parts of the regular expression pattern. These strings may contain characters that have special meaning to the regular expression engine, and for the engine to interpret them literally they need to be escaped, or “quoted.”
This function takes the input string and puts a backslash in front of every character that can be interpreted as part of regular expression syntax. If the optional delimiter parameter ...
Get PHP Functions Essential Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.