3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * PHP DOM and JavaScript with HTML entities * * @link http://stackoverflow.com/q/18487515/367456 */ # 3v4l.org low php version stopper if (version_compare(PHP_VERSION, '5.0.5', '<=')) return; $doc = new DOMDocument("1.0"); $doc->loadXML('<head/>'); $javascriptCode = "\n if (1 < 4) {\n alert(\"hello\");\n }\n"; $script = $doc->createElement('script'); $script->appendChild($doc->createCDATASection($javascriptCode)); $heads = $doc->getElementsByTagName('head'); $head = $heads->item(0); $scriptInHead = $head->appendChild($script); echo 'libxml: ', LIBXML_DOTTED_VERSION, "\n" , "\nXML:\n", $doc->saveXML() , "\nHTML:\n", $doc->saveHTML() ;

preferences:
47.72 ms | 402 KiB | 5 Q