[php-src] Issue #24349: libxml update on Linux systems changes behavior of DOMDocument->loadHTML

From: Date: Thu, 15 Oct 2026 12:45:24 +0000
Subject: [php-src] Issue #24349: libxml update on Linux systems changes behavior of DOMDocument->loadHTML
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253000@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/24349 Author: DanielRuf ### Description The following code: ```php <?php public function clean($html) { ... $doc = new \DOMDocument(); $doc->loadHTML( '<?xml encoding="utf-8" ?><body>'. $valid .'</body>', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD ); $this->cleanNode($doc->getElementsByTagName('body')->item(0)); $doc->formatOutput = true; $filtered = $doc->saveHTML(); $clean = str_replace(array('<?xml encoding="utf-8" ?><body>', '</body>'), '', $filtered); ... } ``` Resulted in this output: ``` <!--?xml encoding="utf-8" ?--><body> <span>test ``` But I expected this output instead: ``` <span>test ``` It seems it now handles HTML code and does not need this XML trick anymore (because libxml now seems to convert <?xml to <!--?xml . So what is the right solution to have the same result for PHP 8.1 - PHP 8.5? ### PHP Version ```plain PHP 8.5.9-dev (cli) (built: Jun 21 2026 23:58:16) (ZTS Visual C++ 2022 x64) Copyright (c) The PHP Group Zend Engine v4.5.9-dev, Copyright (c) Zend Technologies with Xdebug v3.5.0, Copyright (c) 2002-2025, by Derick Rethans with Zend OPcache v8.5.9-dev, Copyright (c), by Zend Technologie ``` ### Operating System Ubuntu 26.04

« previous php.bugs (#253000) next »