How can the use of "@" in the loadHTMLFile() method be avoided to handle warnings more effectively?

When using the loadHTMLFile() method in PHP, warnings can be handled more effectively by using the error suppression operator "@" to prevent the warnings from being displayed. However, a better approach would be to use the libxml_use_internal_errors() function to suppress the warnings and then check for any errors after loading the HTML file.

// Suppress warnings using libxml_use_internal_errors()
libxml_use_internal_errors(true);

// Load the HTML file
$doc = new DOMDocument();
$doc->loadHTMLFile('example.html');

// Check for any errors
$errors = libxml_get_errors();

// Handle errors if needed
if (!empty($errors)) {
    foreach ($errors as $error) {
        // Handle error here
    }
}

// Clear any errors
libxml_clear_errors();