我使用 xpath 删除 <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>
我怎样才能删除它们?
或者也许是我应该使用的正则表达式?
最佳答案
试试
$nodeList = $xpath->query("//p[normalize-space(.)=\"\xC2\xA0\"]"); #
foreach($nodeList as $node)
{
$node->parentNode->removeChild($node);
}
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.
关于php - 使用 XPATH 删除 <p><strong><br/> </strong></p>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7856414/