用preg_replace替换ereg_replace [英] replace ereg_replace with preg_replace
问题描述
您需要将函数ereg_replace("[\]", "", $theData)
更改为preg_replace
Hi need to change the function ereg_replace("[\]", "", $theData)
to preg_replace
推荐答案
要将端口ereg_replace
移植到preg_replace
,您需要将正则表达式放在一对定界符
To port ereg_replace
to preg_replace
you need to put the regex between a pair of delimiter
您的regx是[\]
,无效,将用于preg_replace,因为\
正在转义结束字符类]
Also your regx is [\]
is invalid to be used for preg_replace as the \
is escaping the closing char class ]
正确的端口是
preg_replace('/[\\\]/','',$theData)
此外,由于char类只有一个char,因此对char类没有真正的需求,您可以说:
Also since the char class has just one char there is no real need of char class you can just say:
preg_replace('/\\\/','',$theData)
由于只替换一个字符,因此不建议使用正则表达式.您应该使用str_replace
as
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);
这篇关于用preg_replace替换ereg_replace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!