我正在使用file_get_contents()来访问一个URL。
file_get_contents('http://somenotrealurl.com/notrealpage');
如果URL不存在,它会返回这个错误信息。我该如何让它优雅地报错,以便我知道页面不存在并根据情况采取行动,而不显示这个错误信息?
file_get_contents('http://somenotrealurl.com/notrealpage')
[function.file-get-contents]:
failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
in myphppage.php on line 3
例如在Zend中,您可以这样说:if ($request->isSuccessful())
$client = New Zend_Http_Client();
$client->setUri('http://someurl.com/somepage');
$request = $client->request();
if ($request->isSuccessful()) {
//do stuff with the result
}