- printf: documentation ( source)
<?php
$html = <<<HTML
<div>
<div>
<p> ... </p>
</div>
</div>
HTML;
$dom = new DOMDocument;
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('//*');
foreach ($nodes as $node) {
printf(
"Nodes in List: %d \n" .
"Current Tag: %s \n" .
"Current Parent: %s \n\n",
$nodes->length,
$node->tagName,
$node->parentNode->tagName
);
$node->parentNode->removeChild($node);
}
echo $dom->saveHtml();