When parsing non-well-formed HTML with DomDocument, PHP often displays warnings. If you wish to avoid these debugging messages, you can disable them programmatically.
To suppress warnings during HTML loading, modify your code as follows:
<?php // enable internal error handling libxml_use_internal_errors(true); // create a DOM document and load the HTML data $xmlDoc = new DomDocument; $xmlDoc->loadHTML($fetchResult); // check for errors and handle them yourself $errors = libxml_get_errors(); foreach ($errors as $error) { // handle the errors as you wish } ?>
By enabling internal error handling (via libxml_use_internal_errors()), libxml2 will not output errors and warnings to PHP. You can then retrieve and handle these errors manually using libxml_get_errors().
The above is the detailed content of How Can I Suppress Warnings When Parsing Non-Well-Formed HTML With DomDocument (PHP)?. For more information, please follow other related articles on the PHP Chinese website!