相关疑难解决方法(0)

如果XML文件为空,则捕获PHP错误

所以我从XML文件中抓取一些信息,如下所示:

$url = "http://myurl.blah";
$xml = simplexml_load_file($url);
Run Code Online (Sandbox Code Playgroud)

除了有时XML文件是空的,我需要代码优雅地失败,但我似乎无法弄清楚如何捕获PHP错误.我试过这个:

if(isset(simplexml_load_file($url)));
{
    $xml = simplexml_load_file($url);
    /*rest of code using $xml*/
}
else {
    echo "No info avilable.";
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.我想你不能那样使用ISSET.任何人都知道如何捕获错误?

php xml error-handling

2
推荐指数
1
解决办法
7631
查看次数

标签 统计

error-handling ×1

php ×1

xml ×1