note 97009 modified in function.file-get-contents by thiago
| From: | thiago@php.net | Date: | Tue, 01 Jun 2010 04:10:51 +0000 |
| Subject: | note 97009 modified in function.file-get-contents by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-169760@lists.php.net to get a copy of this message | ||
If you want to check if the function returned error, in case of a HTTP request an, it's not
sufficient to test it against false. It may happen the return for that HTTP request was empty. In
this case it's better to check if the return value is a bool.
<?php
$result=file_get_contents("http://www.example.com");
if ($result === false)
{
// treat error
} else {
// handle good case
}
?>
[EDIT BY thiago: Has enhacements from an anonymous user]
--was--
If you want to check if the function returned error, in case of a HTTP request an, it's not
sufficient to test it against false. It may happen the return for that HTTP request was empty. In
this case it's better to check if the return value is a bool.
<?php
$result=file_get_contents("http://www.example.com");
if (is_bool($result) && $result == false)
{
// treat error
} else {
// handle good case
}
?>
http://php.net/manual/en/function.file-get-contents.php