Php 如何替换样式并将其添加到特定标记中
我有个问题。我不能替换和添加内联样式的css。 我有这个 输入:Php 如何替换样式并将其添加到特定标记中,php,regex,Php,Regex,我有个问题。我不能替换和添加内联样式的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 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>
hello world测试 我想要这个 输出:
<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>
hello world测试 我试过这种方法
$re=“/(]+\”([^>\“]+)/miu”;
$str=“hello world
\n测试
\n\n”;
$subst=“$1$2margin:0;”;
$result=preg_replace($re,$subst,$str);
任何人都请帮助我。谢谢。我已经解决了这个问题:
<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>
按正则表达式模式搜索((?您是否考虑过使用
DOM
?不,只有preg_replace。最后2行不匹配&不替换。请查看演示为什么您不能自己修改字符串?@self我不知道高级正则表达式