- simplexml_import_dom: documentation ( source)
<?php
$str = <<<EOT
<html>
<body>
<img src="img1.jpg" />
<img src="img2.jpg" />
<a href="#"> link 1</a>
<a href="page.HTML">link 2</a>
</body>
</html>
EOT;
$d = new DOMDocument();
$d->loadHTML($str);
$sx = simplexml_import_dom($d);
foreach ($sx->xpath('') as $v) {
echo $v->getName() . "\n";
}