- print_r: documentation ( source)
- libxml_use_internal_errors: documentation ( source)
<?php
$html = '<html><body>
<a href="a.html">some a</a>
<a href="b.html">some b</a>
</body></html>';
libxml_use_internal_errors(true); // ignore malformed HTML
$xml = new DOMDocument();
$xml->loadHTML($html);
foreach($xml->getElementsByTagName('a') as $link) {
$link->nodeValue = $link->nodeValue . ' --- ' . $link->getAttribute('href');
}
print_r($xml->saveHtml());