note 97009 modified in function.file-get-contents by thiago

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.