note 121314 deleted from function.simplexml-load-string by cmb
| From: | cmb@php.net | Date: | Sun, 15 Dec 2019 10:12:05 +0000 |
| Subject: | note 121314 deleted from function.simplexml-load-string by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213528@lists.php.net to get a copy of this message | ||
Note Submitter: oirinth
----
A simple way of checking if the XML string is valid is to suppress the warnings on the
simplexml_load_string() and then check the boolean return for an error.
$sxml = @simplexml_load_string($xml_str_to_test);
if ($sxml !== false )
{
// string is valid XML
// to confirm this by eye, write the xml to the php error log as a string
error_log( print_r($sxml->asXML(),true));
} else
{
// invalid XML, throw an error or something
}