so I'm grabbing some information from an XML file like so:
$url = "http://myurl.blah";
$xml = simplexml_load_file($url);
Except sometimes the XML file is empty and I need the code to fail gracefully but I can't seem to figure out how to catch the PHP error. I tried this:
if(isset(simplexml_load_file($url)));
{
$xml = simplexml_load_file($url);
/*rest of code using $xml*/
}
else {
echo "No info avilable.";
}
But it doesn't work. I guess you can't use ISSET that way. Anyone know how to catch the error?
From PHP manual, error handling (click here):
Or, possibly slightly more efficient, but not necessarily recommended because it silences errors:
Don't use
isset
here.