I would like to escape multiple characters. In perl I would do:
s/([\&;`'\|"*?~<>()[]{}\$\n\r])/\$1/g;
So that:
&;`'\"|*?~<>()[]{}$\n\r will get escaped with a \
However I can't seem to do thin in php.
I've tried using preg_replace like:
$pattern = "([\&;`'\|\"*?~<>()[]{}\$\n\r])";
$var = preg_replace("/$pattern/", "\$1", $var);
However the preg regex engine doesn't seem to like the $1 notation. (I know it performs the match because if it change \$1 to something like "M" it will replace the correct characters with M.
Anyone know how to do this (I know I could use escapeshellarg or cmd but I would like the ability to add symbols as I need them.
Thanks.