I use xpath to remove <p> </p>
$nodeList = $xpath->query("//p[text()=\"\xC2\xA0\"]"); #
foreach($nodeList as $node)
{
$node->parentNode->removeChild($node);
}
but it does not remove this,
<p><strong><br /> </strong></p>
or this kind,
<p><strong> </strong></p>
How can I remove them?
Or maybe a regex that I should use?
The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter. Note: This function is binary-safe.
The line break can be removed from string by using str_replace() function.
The HTML tags can be removed from a given string by using replaceAll() method of String class. We can remove the HTML tags from a given string by using a regular expression. After removing the HTML tags from a string, it will return a string as normal text.
you can use strip_tags($string) to strip the html tags.
Try with
$nodeList = $xpath->query("//p[normalize-space(.)=\"\xC2\xA0\"]"); #
foreach($nodeList as $node)
{
$node->parentNode->removeChild($node);
}
Quoting from the docs
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With