将 ereg_replace 替换为 preg_replace
您好,需要将函数 ereg_replace("[\]", "", $theData)
更改为 preg_replace
Hi need to change the function ereg_replace("[\]", "", $theData)
to preg_replace
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要将
ereg_replace
移植到preg_replace
,您需要将正则表达式放在一对 delimiter 之间,而且您的正则表达式是
[\]
用于 preg_replace 无效,因为\
正在转义结束 char 类]
正确的端口是
Also,因为 char 类刚刚一个字符并不真正需要 char 类,您可以只是说:
由于您只替换一个字符,因此不建议使用正则表达式。您应该使用
str_replace
进行简单的文本替换,如下所示:To port
ereg_replace
topreg_replace
you need to put the regex between a pair of delimiterAlso your regx is
[\]
is invalid to be used for preg_replace as the\
is escaping the closing char class]
The correct port is
Also since the char class has just one char there is no real need of char class you can just say:
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:但我严重怀疑你根本不需要更换。您很可能需要一些其他操作。
这个替换是做什么用的?
But I seriously doubt you need that replace at all. most likely you need some other operation.
What is this replace for?
我使用此 sed 自动将 ereg_replace 替换为 preg_replace 并放入所需的斜杠。假设第一个正则表达式中没有 \"
I used this sed to automatically replace ereg_replace by preg_replace and put the required slashes in. Assumes no \" in the first regex