Marco.org

I’m : a programmer, writer, podcaster, geek, and coffee enthusiast.

The holy grail of PHP XML processing!

libxml_use_internal_errors(true)

This single function, added in PHP 5.1.0, will save me so much grief, it’s beyond words.

Ever use $dom->loadHTML($crappy_html_code) to get a website’s content into an XML DOM for parsing or other processing? Normally, every unescaped ampersand and misplaced P tag would generate a PHP warning, just like xsltproc, which made it extremely difficult to use these functions without having a bunch of special-case error-handling routines to ignore these pointless warnings.

Now, we can turn those stupid warnings off, and can safely call ->loadHTML() on anything and have it quietly return false if it has so much trouble that it actually matters.