Based on @Tak's answer and @FrancisAvila's comment, I found that these snippings work better for me:
while (true) { $dom = new DOMDocument(); if (libxml_use_internal_errors(true) === true)
This has the following advantages: 1) do not discard parsing errors last if you ever need to access them through libxml_get_errors() , and 2) calling libxml_clear_errors() only if necessary, since libxml_use_internal_errors() returns the previous configuration state.
source share