相关疑难解决方法(0)

url不存在时的file_get_contents

我正在使用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)

php file-get-contents

69
推荐指数
7
解决办法
8万
查看次数

标签 统计

file-get-contents ×1

php ×1