删除< p>< strong>< br /> & nbsp;< / strong&am

编程入门 行业动态 更新时间:2024-10-27 10:27:29
本文介绍了删除< 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;

本文发布于:2023-09-12 06:28:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466870.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:gt   lt   amp   strong   XPATH

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!