Klaas Sangers Klaas Sangers - 3 months ago 15
PHP Question

PHP DOMDocument errors/warnings on html5-tags

I've been attempting to parse HTML5-code so I can set attributes/values within the code, but it seems DOMDocument(PHP5.3) doesn't support tags like


Is there any way to parse this as HTML in PHP and manipulate the code?

Code to reproduce:

$dom = new DOMDocument();
$dom->loadHTML("<!DOCTYPE HTML>


Warning: DOMDocument::loadHTML(): Tag
nav invalid in Entity, line: 4 in
on line 17

Warning: DOMDocument::loadHTML(): Tag
section invalid in Entity, line: 10 in
on line 17


No, there is no way of specifying a particular doctype to use, or to modify the requirements of the existing one.

Your best workable solution is going to be to disable error reporting with libxml_use_internal_errors:

$dom = new DOMDocument;

or use html5lib instead of the DOM extension (note that this is described as 'currently unmaintained since April 9, 2013!).