I am wondering if it is possible to have an if statement something like this:
if file_get_contents() returns error code xxx OR xxx die();
I'm not sure how to check if an file_get_contents()error returns .
file_get_contents()
It seems you want to get an HTTP status code. In this case, you need to read it here:
$http_response_header
http://php.net/manual/en/reserved.variables.httpresponseheader.php
Otherwise, if you want to get a general error, follow the deceze instructions.
http://php.net/file_get_contentsThe function returns read data or FALSE on failure.
http://php.net/file_get_contents
The function returns read data or FALSE on failure.
This either works or not, as such:
$file = file_get_contents(...); if ($file === false) { die(); }
PS: , , file_get_contents . HTTP URL-, cURL HTTP .
file_get_contents
How ? Php the docs , file_get_contents()will return falsefor any errors, so all you can do is
false
if ($content=file_get_contents($filename)===false) die("Error reading file $filename");
you can call it that:
$data = file_get_contents("http://site.com/that.php"); if ($data !== FALSE) { // analyze data }