删除< p>< strong>< br /> & nbsp;< / strong>< / p>用XPATH [英] Remove <p><strong><br />  </strong></p> with XPATH

查看:225
本文介绍了删除< 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);
}






引用 来自文档


normalize-space 函数返回已标准化
空格的参数字符串通过去除前导和尾随空格,以及
将空格字符序列替换为单个空格。

The normalize-space function returns the argument string with whitespace normalized by stripping leading and trailing whitespace and replacing sequences of whitespace characters by a single space.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆