我想删除所有 <br>
<p></p>
之外的标签.但是在<p></p>
里面休息不应该受到伤害。我怎样才能在 php 中实现这个。下面是一个例子。
$html = "<br> <p> This is the Firs para <br>
This is a line after the first break <br>
This is the line after the 2nd break <br>
Here the first para ends </p>
<br>
<br>
<p> This is the 2nd para <br>
This is a line after the first break in 2nd para <br>
This is the line after the 2nd break <br>
Here the 2nd para ends </p>"
我想要的结果如下
$html = "<p> This is the Firs para <br>
This is a line after the first break <br>
This is the line after the 2nd break <br>
Here the first para ends </p>
<p> This is the 2nd para <br>
This is a line after the first break in 2nd para <br>
This is the line after the 2nd break <br>
Here the 2nd para ends </p>"
最佳答案
这对你有帮助。
$out = preg_replace("(<p(?:\s+\w+(?:=\w+|\"[^\"]+\"|'[^']+')?)*>.*?</p>(*SKIP)(*FAIL)"
."|<br>)is", "", $html);
echo $out;
关于php - 如何从段落外删除分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45568398/