Is there a canonical function/method for escaping a string to be used in a preg_
, such that any special PCRE characters will be interpreted as literal. Basically, a know way to ensure that something like
I am a fancy string (well, that guy ... said I was fancy)
is transformed into
I am a fancy string \(well, that guy \.\.\. said I was fancy\)
The use case is something like
$re = get_string_from_somewhere();
$re = our_magic_function($re);
preg_match_all('%'.$re.'%',$string, $matches);