如何删除此空<;p><;span>&;nbsp</span></p>;使用正则表达


How to remove this empty <p><span>&nbsp;</span></p> tag using regular expression and php

我有一个要求,我需要从一段文本中删除它。

<p><span>&nbsp;</span></p>

例如

<p><span>Because the coffee grinds stay in the pod there is virtually no cleaning either.</span></p>
<p><span>&nbsp;</span></p>
<p><span>Hey presto, your coffee, your way every time. </span></p>.

我已尝试删除空

<p></p> 

使用正则表达式

$pattern1 = "/<p[^>]*><''/p[^>]*>/";

我应该如何修改以删除空标签

<p><span>&nbsp;</span></p>

如果您只需要删除这段代码,那么根本不需要regex。只需使用str_replace 进行简单的替换

$string = str_replace("<p><span>&nbsp;</span></p>", "", $string);