本文介绍了删除< p>< strong>< br /> & nbsp;< / strong>< / p>用XPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用xpath删除< p>& nbsp;< / p>
I use xpath to remove <p> </p>
$nodeList = $xpath->query("//p[text()=\"\xC2\xA0\"]"); # foreach($nodeList as $node) { $node->parentNode->removeChild($node); }但不会删除它,
<p><strong><br /> </strong></p>或这种
<p><strong> </strong></p>如何删除它们?
还是我应该使用的正则表达式?
Or maybe a regex that I should use?
推荐答案尝试
$nodeList = $xpath->query("//p[normalize-space(.)=\"\xC2\xA0\"]"); # 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.
更多推荐
删除< p>< strong>< br /> & nbsp;
发布评论