If we are loading html5 tags such as <section>, <svg> there is following error:
DOMDocument::loadHTML(): Tag section invalid in Entity
We can disable standard libxml errors (and enable user error handling) using libxml_use_internal_errors(true); before loadHTML();
This is quite useful in phpunit custom assertions as given in following example (if using phpunit test cases):
// Create a DOMDocument
$dom = new DOMDocument();
// fix html5/svg errors
libxml_use_internal_errors(true);
// Load html
$dom->loadHTML("<section></section>");
$htmlNodes = $dom->getElementsByTagName('section');
if ($htmlNodes->length == 0) {
$this->assertFalse(TRUE);
} else {
$this->assertTrue(TRUE);
}