Hi , really simple question how can I preg_replace the backslash charactor ?
A:
Escape \
with \
: \\
preg_replace('/\\/', 'REMOVED BACKSLASH', 'sometest\othertest');
Marek Karbarz
2010-02-08 15:34:25
+1
A:
You need to escape the backslash: \\
From the manual on preg_replace():
To use backslash in replacement, it must be doubled ("\\\\" PHP string).
Alternatively, use preg_quote to prepare a string for a preg_* operation.
Pekka
2010-02-08 15:34:49
+1
A:
Yes, but you need to escape it. When using it in the regexp use \\ to use it in the replacement, use \\\\ (that will turn into \\ that will be interpreted as a single backslash).
Johnco
2010-02-08 15:35:45