& nbsp;

using XPATH I use xpath to remove

 

$nodeList = $xpath->query("//p[text()=\"\xC2\...">

Remove <p> <strong> <br/"> & nbsp; </strong> </p> using XPATH

I use xpath to remove <p>&nbsp;</p>

  $nodeList = $xpath->query("//p[text()=\"\xC2\xA0\"]"); # &nbsp; foreach($nodeList as $node) { $node->parentNode->removeChild($node); } 

but he does not delete it,

 <p><strong><br /> &nbsp;</strong></p> 

or such

 <p><strong>&nbsp;</strong></p> 

How to remove them?

Or maybe there is a regex that I should use?

+6
source share
1 answer

Try

 $nodeList = $xpath->query("//p[normalize-space(.)=\"\xC2\xA0\"]"); # &nbsp; foreach($nodeList as $node) { $node->parentNode->removeChild($node); } 

Quote from the docs

The normalize-space function returns an argument string with spaces, normalized by removing leading and trailing spaces and replacing sequences of space characters with one space.

+6
source

Source: https://habr.com/ru/post/899838/


All Articles