我正在使用file_get_contents()来访问URL.
file_get_contents('http://somenotrealurl.com/notrealpage');
Run Code Online (Sandbox Code Playgroud)
如果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
Run Code Online (Sandbox Code Playgroud)
例如在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
}
Run Code Online (Sandbox Code Playgroud)