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 5, PHP 7, PHP 8)
DOMDocument::normalizeDocument — Normalise le document
Cette méthode fonctionne comme si l'on sauvegardait le document puis on le chargeait de nouveau, rendant le document sous une forme "normale".
Cette fonction ne contient aucun paramètre.
Aucune valeur n'est retournée.
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.