Using the LIBXML_NOWARNING options flag doesn\'t stop wanrings when loading html with PHPDOMDocument->loadHTML. Other constants do work though.
In the example below
The LIBXML_NOWARNING option is ignored with DOMDocument::loadHTML() is a bug in PHP (and to be fixed). It has been recently brought up in a related question "libxml htmlParseDocument ignoring htmlParseOption flags" and filed as PHP Bug #74004 LIBXML_NOWARNING flag ingnored on loadHTML*.
You can, however, manage the error handling your own until the bug is fixed:
libxml_use_internal_errors()
.Code example:
$doc = new DOMDocument();
# clear errors list if any
libxml_clear_errors();
# use internal errors, don't spill out warnings
$previous = libxml_use_internal_errors(true);
$doc->loadHTML("Hi
");
echo $doc->saveHTML();
# clear errors list if any
libxml_clear_errors();
# restore previous behavior
libxml_use_internal_errors($previous);
This bug is fixed now.