我有一个问题。 我无法替换和添加内联样式的 CSS。我有这个 输入:
<p style="text-align: justify;"><span style="font-size: 11pt;">hello world<br /></span></p>
<p id="tem" style="text-align: justify;">test</p>
<p > </p>
<p> </p>
我想要这个输出:
<p style="text-align: justify;margin:0;"><span style="font-size: 11pt;">hello world<br /></span></p>
<p id="tem" style="text-align: justify;margin:0;">test</p>
<p style="margin:0;"> </p>
<p style="margin:0;"> </p>
我已经尝试过这种方式演示
$re = "/(<p[^>]+'")([^>'"]+)/miu";
$str = "<p id='"tem'" style='"text-align: justify;'"><span style='"font-size: 11pt;'">hello world<br /></span></p>'n<p style='"text-align: justify;'">test</p>'n<p > </p>'n<p> </p>";
$subst = "$1$2margin:0;";
$result = preg_replace($re, $subst, $str);
请帮助我。谢谢。
我已经解决了:
按正则表达式模式((?<='<)[^>]+style=")([^>"]+)
搜索并替换为$1$2margin:0;
现场演示