如何在Simple HTML Dom Parser

时间:2017-01-08 21:29:49

标签: php html dom simple-html-dom

所以我有了这个,

$r1pro = file_get_html('http://www.example.com/forums-profile.php?user_id='.$uid);
$uname = $r1pro->find('span.username', 0);

它完美无缺,但网站设计得非常好,如果你没有登录,有些请求会返回500错误,输出如下内容:

Warning: file_get_contents(http://www.example.com/forums-profile.php?user_id=12345678): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /home/mysite/public_html/su3/htmldom.php on line 76
Fatal error: Call to a member function find() on boolean in /home/mysite/public_html/su3/index.php on line 61

我已经在simplehtmldom中搜索了错误处理的方法但没有找到任何内容。有没有办法捕获http错误并运行一些不同的代码呢?

1 个答案:

答案 0 :(得分:0)

没关系,我觉得现在真的很蠢。我所要做的只是

if($r1pro){
<--do normal stuff if no error-->
}else{
<--do stuff in case of error-->
}