To hide warnings, you must give special libxml that are used internally for parsing:
libxml_use_internal_errors(true); $dom->loadHTML($html); libxml_clear_errors();
libxml_use_internal_errors(true) indicates that you will handle errors and warnings yourself, and you do not want them to spoil the output of your script.
This is not the same as the @ operator. Warnings are collected behind the scenes, after which you can get them with libxml_get_errors() if you want to register or return a list of problems to the caller.
Regardless of whether you use collected warnings, you should always clear the queue by calling libxml_clear_errors() .
State preservation
If you have other code that uses libxml , you might libxml to make sure that your code does not change the global error handling state; for this you can use the return value of libxml_use_internal_errors() to save the previous state.
// modify state $libxml_previous_state = libxml_use_internal_errors(true); // parse $dom->loadHTML($html); // handle errors libxml_clear_errors(); // restore libxml_use_internal_errors($libxml_previous_state);
Ja͢ck Jul 09 '13 at 22:59 2013-07-09 22:59
source share