gpt4 book ai didi

PHP - 用 preg 替换 ereg

转载 作者:行者123 更新时间:2023-12-04 14:41:08 26 4
gpt4 key购买 nike

我正在尝试从站点中删除一些已弃用的代码。谁能告诉我 preg 相当于

ereg_replace("<b>","<strong>",$content);

谢谢。

最佳答案

似乎根本不需要正则表达式。

一个简单的str_replace会做:

$cleaned = str_replace  ('<b>', '<strong>', $unCleaned);

如果你需要更复杂的替换,例如检查属性,你可以这样做:

$cleaned = preg_replace('/<b(\s[^>]*)?>/', '<strong\\1>', $unCleaned);

但这绝不是完美的;类似 <div title="foo->bar"></div> 的东西会破坏正则表达式。

关于PHP - 用 preg 替换 ereg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1497417/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com