Hi need to change the function ereg_replace("[\]", "", $theData)
to preg_replace
views:
79answers:
4This is wrong, since the \\ will be processed once for the string literal, and then once for the regex, so the result is a literal forward slash, then literal g. Further, there is no g flag.
Matthew Flaschen
2010-09-06 07:05:37
you are right! I mixed up with javascript regexp
Yanick Rochon
2010-09-06 07:09:12
+2
A:
str_replace("\\","",$theData);
But I seriously doubt you need that replace at all. most likely you need some other operation.
What is this replace for?
Col. Shrapnel
2010-09-06 06:56:51
+6
A:
To port ereg_replace
to preg_replace
you need to put the regex between a pair of delimiter
Also your regx is [\]
is invalid to be used for preg_replace as the \
is escaping the closing char class ]
The correct port is
preg_replace('/[\\\]/','',$theData)
Also since the char class has just one char there is no real need of char class you can just say:
preg_replace('/\\\/','',$theData)
Since you are replace just a single char, using regex for this is not recommended. You should be using a simple text replacement using str_replace
as:
str_replace('\\','',$data);
codaddict
2010-09-06 07:10:19
'/\\\/' will lead into escaping the forward slash by preg_replace, you need 4 backslashes
Yanick Rochon
2010-09-06 07:12:55
@Yanick, no it won't. `preg_replace` sees it as /\\/, which it decodes as a literal backslash within delimiters. Note that '/\\\\/' is *also* correct, because \\ and \ can both encode a backslash in a string literal. Note that \/ is not a string escape.
Matthew Flaschen
2010-09-06 07:23:16