You can use this in this way.
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->loadHTML($content); // html content
$xpath = new DOMXPath($doc);
$doc->normalizeDocument();
Note that, you can use $doc->normalizeDocument(); at any point of time.
PHP - Manual: DOMDocument::normalizeDocument
2024-11-22
(PHP 5, PHP 7, PHP 8)
DOMDocument::normalizeDocument — Normalizes the document
This method acts as if you saved and then loaded the document, putting the document in a "normal" form.
此函数没有参数。
没有返回值。
You can use this in this way.
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->loadHTML($content); // html content
$xpath = new DOMXPath($doc);
$doc->normalizeDocument();
Note that, you can use $doc->normalizeDocument(); at any point of time.
官方地址:https://www.php.net/manual/en/domdocument.normalizedocument.php