$subcontent = '';
@$dom->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
foreach($dom->getElementsByTagName('*') as $node) {
$subcontent .= $dom->saveHTML($node);
}
echo $subcontent;
$entry = $xpath->query('//div[contains(@id, \'entry\')]/div');
$content = '';
foreach($entry as $element) {
if(! $xpath->evaluate("contains(@class, 'foo')", $element)) {
$content .= $dom->saveHTML($element) . PHP_EOL;
}
}
echo $content;
//<div class="world bar">bla bla bla</div>
//<div class="two bar">bla bla bla</div>
//<div class="paper bar">bla bla bla</div>
//<div class="boo bar loo">bla bla bla</div>
https://3v4l.org/FhNUp