-
Notifications
You must be signed in to change notification settings - Fork 114
Parser Errors
Ilhan Yumer edited this page May 16, 2022
·
4 revisions
A html5 document with errors can still be parsed and a DOM can be returned. Errors do not stop parsing. They are recorded as parser errors and the parser continues parsing. Some malformed html will cause parser errors and return a DOM looking different than you expect.
If there are errors they are available on the returned DOM as an array on the errors
property. For example:
$html = <<< 'HERE'
<html>
<head>
<title>test</title>
</head>
<body>
<p>This is a test of the HTML5 parser.</p>
</body>
</html>
HERE;
$html5 = new HTML5();
$dom = $html5->loadHTML($html);
print_r($html5->getErrors());
Will produce the error:
Array
(
[0] => Line 0, Col 0: No DOCTYPE specified.
)
Note: This parser is not a validating parser. To validate markup try the w3 validator.