How can the issue of an "Empty string supplied as input" be resolved when using DOMDocument::loadHTML() in PHP?

When using DOMDocument::loadHTML() in PHP, the "Empty string supplied as input" issue occurs when the function is called with an empty string as the input parameter. To resolve this issue, you can check if the input string is empty before calling the function to avoid the error.

$html = ""; // empty string input
if (!empty($html)) {
    $dom = new DOMDocument();
    $dom->loadHTML($html);
    // continue processing the HTML document
} else {
    echo "Input string is empty.";
}