note 117237 added to function.simplexml-load-string

From: Date: Thu, 07 May 2015 15:38:07 +0000
Subject: note 117237 added to function.simplexml-load-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-202467@lists.php.net to get a copy of this message
Be careful checking for parse errors. An empty SimpleXMLElement may resolve to FALSE, and if your XML contains no text or only contains namespaced elements your error check may be wrong. Always use === FALSE when checking for parse errors. <?php $xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <ns1:Root xmlns:ns1="http://example.com/custom"> <ns1:Node>There's stuff here</ns1:Node> </ns1:Root> XML; $simplexml = simplexml_load_string($xml); // This prints "Parse Error". echo ($simplexml ? 'Valid XML' : 'Parse Error'), PHP_EOL; // But this prints "There's stuff here", proving that // the SimpleXML object was created successfully. echo $simplexml->children('http://example.com/custom')->Node, PHP_EOL; // Use this instead: echo ($simplexml !== FALSE ? 'Valid XML' : 'Parse Error'), PHP_EOL; ?> See: https://bugs.php.net/bug.php?id=31045 https://bugs.php.net/bug.php?id=30972 https://bugs.php.net/bug.php?id=69596 ---- Server IP: 195.54.192.44 Probable Submitter: 205.221.255.62 ---- Manual Page -- http://php.net/manual/en/function.simplexml-load-string.php Edit -- https://master.php.net/note/edit/117237 Del: integrated -- https://master.php.net/note/delete/117237/integrated Del: useless -- https://master.php.net/note/delete/117237/useless Del: bad code -- https://master.php.net/note/delete/117237/bad+code Del: spam -- https://master.php.net/note/delete/117237/spam Del: non-english -- https://master.php.net/note/delete/117237/non-english Del: in docs -- https://master.php.net/note/delete/117237/in+docs Del: other reasons-- https://master.php.net/note/delete/117237 Reject -- https://master.php.net/note/reject/117237 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202467) next »