When loading HTML content into a DOMDocument, you may encounter the warning "htmlParseEntityRef: expecting ';' in Entity." This error often arises due to malformed HTML entities in the loaded content. To alleviate this warning while ensuring proper entity resolution, follow these steps:
By employing this technique, the warning will be suppressed, and the DOMDocument will be correctly populated with the loaded HTML content.
// create new DOMDocument
$document = new \DOMDocument('1.0', 'UTF-8');
// set error level
$internalErrors = libxml_use_internal_errors(true);
// load HTML
$document->loadHTML($html);
// Restore error level
libxml_use_internal_errors($internalErrors);
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3