3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Checks if a XML file's structure is valid. * @author Julius Beckmann <php@h4cc.de> * @param $file string * @return bool */ function isXmlStructureValid($file) { $prev = libxml_use_internal_errors(true); $ret = true; try { new SimpleXMLElement($file, 0, true); } catch(Exception $e) { $ret = false; } if(count(libxml_get_errors()) > 0) { // There has been XML errors $ret = false; } // Tidy up. libxml_clear_errors(); libxml_use_internal_errors($prev); return $ret; } $xml = '<html> <head><title>411 Length Required</title></head> <body bgcolor="white"> <center><h1>411 Length Required</h1></center> <hr><center>nginx</center> </body> </html>'; var_dump(isXmlStructureValid($xml));

preferences:
35.63 ms | 402 KiB | 5 Q