本文介绍了删除< p>< strong>< br /> & nbsp;< / strong>< / p>用XPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用xpath删除< p>& nbsp;< / p>

I use xpath to remove <p>&nbsp;</p>

    $nodeList = $xpath->query("//p[text()=\"\xC2\xA0\"]"); # &nbsp;
    foreach($nodeList as $node)
    {
        $node->parentNode->removeChild($node);
    }

但不会删除它,

<p><strong><br /> &nbsp;</strong></p>

或这种

<p><strong>&nbsp;</strong></p>

如何删除它们?

还是我应该使用的正则表达式?

Or maybe a regex that I should use?

推荐答案

尝试

$nodeList = $xpath->query("//p[normalize-space(.)=\"\xC2\xA0\"]"); # &nbsp;
foreach($nodeList as $node)
{
    $node->parentNode->removeChild($node);
}






引用

这篇关于删除&lt; p&gt;&lt; strong&gt;&lt; br /&gt; &amp; nbsp;&lt; / strong&gt;&lt; / p&gt;用XPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 02:54