PHP - 用 preg 替换 ereg
我正在尝试从网站中删除一些已弃用的代码。 谁能告诉我相当于
ereg_replace("<b>","<strong>",$content);
谢谢的preg。
I'm trying to remove some deprecated code from a site.
Can anyone tell me the preg equivalent of
ereg_replace("<b>","<strong>",$content);
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎根本不需要正则表达式。
一个简单的 str_replace 就可以了:
如果您需要更复杂的替换,例如检查属性,你可以这样做:
但这绝不是完美的;像
这样的东西会破坏正则表达式。
There seems to be no need for regular expressions at all.
a simple str_replace would do:
If you need more complicated replacements, for example checking the attributes, you could do:
But this is by no means perfect; something like
<div title="foo->bar"></div>
would break the regular expression.与 ERE 正则表达式等效的 PCRE 是:
但正如 Jacco 已经指出的那样,您根本不需要正则表达式,因为您想要替换常量值。
A PCRE equivalent to your ERE regular expression would be:
But as Jacco already noted you don’t need a regular expression at all as you want to replace a constant value.