3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = '<p>àâäçß</p>'; $wrapper = "\xEF\xBB\xBF<html><head><meta charset=\"not a charset\" /></head><body>%s</body></html>"; $dom = new DOMDocument; $dom->loadHTML(sprintf($wrapper, $html), \LIBXML_NOWARNING); $result = ''; $childNodes = $dom->getElementsByTagName('body')->item(0)->childNodes; foreach ( $childNodes as $childNode ) { $result .= $dom->saveHTML($childNode); } echo $result;
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Warning: DOMDocument::loadHTML(): htmlCheckEncoding: unknown encoding not a charset in Entity, line: 1 in /in/k6Ekl on line 8 <p>àâäçß</p>

preferences:
75.11 ms | 1261 KiB | 4 Q