3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<?xml version="1.0" encoding="UTF-8"?> <root>Тест кириллицы</root> '; $original = new DOMDocument; $original->loadXML($xml); echo $original->saveXML(); echo PHP_EOL . PHP_EOL; // this is code from \SebastianBergmann\Comparator\DOMNodeComparator::nodeToText $document = new DOMDocument; @$document->loadXML($original->C14N()); echo $document->saveXML(); echo PHP_EOL . PHP_EOL; // if I add utf-8 xml header then document is good $document = new DOMDocument; @$document->loadXML('<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . $original->C14N()); echo $document->saveXML();
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
<?xml version="1.0" encoding="UTF-8"?> <root>Тест кириллицы</root> <?xml version="1.0"?> <root>&#x422;&#x435;&#x441;&#x442; &#x43A;&#x438;&#x440;&#x438;&#x43B;&#x43B;&#x438;&#x446;&#x44B;</root> <?xml version="1.0" encoding="UTF-8"?> <root>Тест кириллицы</root>

preferences:
81.75 ms | 408 KiB | 5 Q