I am trying to avoid a string for use in regex in PHP. So far I have tried:
preg_quote(addslashes($string));
I thought that I needed addslashes to correctly consider any quotes that are in the string. Then preg_quote characters.
However, the problem is that the quotes are escaped with a backslash, for example. \' . But then preg_quote removes the backslash from another, for example. \\' . Thus, this once again returns the quote. Switching two functions does not work either because it would leave an unprocessed backslash, which is then interpreted as a special regular expression character.
Is there a function in PHP to complete a task? Or how to do it?
source share