I need to write a function that does exactly opposite of preg_quote function. Simply removing all ‘\’ did not work because there can be a ‘\’ in the string.
Example;
inverse_preg_quote('an\\y s\.tri\*ng') //this should return "an\y s.tri*ng"
or you can test as
inverse_preg_quote(preg_quote($string)) //$string shouldn't change
You are looking for stripslashes
See http://php.net/manual/en/function.stripslashes.php for more info.
( There’s also the slightly more versatile http://www.php.net/manual/en/function.addcslashes.php and http://www.php.net/manual/en/function.stripcslashes.php you might want to look into )
Edit: otherwise, you could do three str_replace calls. The first to replace \\ with e.g. $DOUBLESLASH, and then replace \ with “” (empty string), then set $DOUBLESLASH back to \.
See http://php.net/manual/en/function.str-replace.php for more info.