note 97009 deleted from function.file-get-contents by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 14:38:24 +0000 |
| Subject: | note 97009 deleted from function.file-get-contents by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215240@lists.php.net to get a copy of this message | ||
Note Submitter: vlad dot wing at gmail dot com
----
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]