使用与simplehtmldom脚本代码(http://simplehtmldom.sourceforge.net/manual.htm):PHP处理错误
function file_get_html() {
$dom = new simple_html_dom;
$args = func_get_args();
$dom->load(call_user_func_array('file_get_contents', $args), true);
return $dom;
}
$url = 'http://site.com/';
$html = file_get_html($url);
如何处理错误回报上file_get_html($url)
一部分?现在,如果页面不存在,它会在浏览器窗口中显示错误。我更喜欢赶上它们,并显示我的文字,如:
if(some error happened on file_get_html($url)) {
$errors = true;
} else {
html = file_get_html($url);
}
谢谢。
请详细介绍catch()部分。 $ e-> getMessage() - 这是什么意思? – James 2010-08-11 13:28:22
似乎不起作用,给出了一个错误(像以前一样):未能打开流:HTTP请求失败! HTTP/1.1 404 Not Found – James 2010-08-11 13:29:45
我认为简单的HTML DOM解析器不会抛出任何异常。 – Gumbo 2010-08-11 13:30:35