This snippet shows how to remove HTML elements using DOMDocument in PHP. The problem is that you can't do it in the same loop.
Source code viewer
$nodes = $dom->getElementsByTagName('td'); foreach ($nodes as $node) { foreach ($node->attributes as $attribute) { if ($attribute->name == 'class') { $remove_elements[] = $node; } } } foreach ($remove_elements as $element) { $element->parentNode->removeChild($element); }Programming Language: PHP