Remove <p> <strong> <br/"> & nbsp; </strong> </p> using XPATH
I use xpath to remove <p> </p>
$nodeList = $xpath->query("//p[text()=\"\xC2\xA0\"]"); # foreach($nodeList as $node) { $node->parentNode->removeChild($node); } but he does not delete it,
<p><strong><br /> </strong></p> or such
<p><strong> </strong></p> How to remove them?
Or maybe there is a regex that I should use?
+6
1 answer
Try
$nodeList = $xpath->query("//p[normalize-space(.)=\"\xC2\xA0\"]"); # foreach($nodeList as $node) { $node->parentNode->removeChild($node); } Quote from the docs
The
normalize-spacefunction returns an argument string with spaces, normalized by removing leading and trailing spaces and replacing sequences of space characters with one space.
+6