Using SimpleXML with HTML

PHP 5's SimpleXML module is one of the the biggest reasons to upgrade to 5. If you're parsing RSS feeds or the results of webservice requests it works beautifully and saves a ton of time. The only problem with it is that it'll only load valid XML. I banged my head against it for way to long before coming up with the following:

<?php
  $doc
= new DOMDocument();
 
$doc->strictErrorChecking = FALSE;
 
$doc->loadHTML($html);
 
$xml = simplexml_import_dom($doc);
?>

Great little nugget, exactly

Great little nugget, exactly what I was looking for, thank you!

for you, a photo

Brad the underwear model

ads

User login