如何使用 PHP 和正则表达式将 <span style="font-weight: bold;">foo</span> 替换为 <strong>foo</strong>?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2728789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:29:40 来源:igfitidea点击:
How to replace <span style="font-weight: bold;">foo</span> by <strong>foo</strong> using PHP and regex?
提问by anon
I have a string like this:
我有一个这样的字符串:
<span style="font-weight: bold;">Foo</span>
I want to use PHP to make it
我想用PHP来实现
<strong>Foo</strong>
…without affecting other spans.
…不影响其他spans。
How can I do this?
我怎样才能做到这一点?
回答by YOU
$text='<span style="font-weight: bold;">Foo</span>';
$text=preg_replace( '/<span style="font-weight: bold;">(.*?)<\/span>/', '<strong></strong>',$text);
Note: only work for your example.
注意:仅适用于您的示例。

