Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何替换<;span style=";字体大小:粗体&引用&燃气轮机;富</span>;由<;strong>;富</strong>;使用PHP和正则表达式?_Php_Regex_Preg Replace - Fatal编程技术网

如何替换<;span style=";字体大小:粗体&引用&燃气轮机;富</span>;由<;strong>;富</strong>;使用PHP和正则表达式?

如何替换<;span style=";字体大小:粗体&引用&燃气轮机;富</span>;由<;strong>;富</strong>;使用PHP和正则表达式?,php,regex,preg-replace,Php,Regex,Preg Replace,我有这样一个字符串: <span style="font-weight: bold;">Foo</span> Foo 我想用PHP来实现它 <strong>Foo</strong> Foo …不影响其他spans 我如何才能做到这一点?$text='Foo'; $text='<span style="font-weight: bold;">Foo</span>'; $text=preg_replace( '/<

我有这样一个字符串:

<span style="font-weight: bold;">Foo</span>
Foo
我想用PHP来实现它

<strong>Foo</strong>
Foo
…不影响其他
span
s

我如何才能做到这一点?

$text='Foo';
$text='<span style="font-weight: bold;">Foo</span>';
$text=preg_replace( '/<span style="font-weight: bold;">(.*?)<\/span>/', '<strong>$1</strong>',$text);
$text=preg_replace(“/(.*?/”,“$1”,$text);

注意:仅适用于您的示例。

使用dom解析器而不是正则表达式。@请不要等到遇到
span style=“font-weight:bold;”“
(注意:和粗体之间缺少空格)或
span style=“color:red;font-weight:bold;”“
或任何其他完全有效的html。