To hide the warnings, you have to give special instructions to
libxml which is used internally to perform the parsing:
libxml_use_internal_errors(true) indicates that you're going to handle the errors and warnings yourself and you don't want them to mess up the output of your script.
This is not the same as the
@ operator. The warnings get collected behind the scenes and afterwards you can retrieve them by using
libxml_get_errors() in case you wish to perform logging or return the list of issues to the caller.
Whether or not you're using the collected warnings you should always clear the queue by calling
Preserving the state
If you have other code that uses
libxml it may be worthwhile to make sure your code doesn't alter the global state of the error handling; 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);
// handle errors