note 117809 added to function.feof
| From: | line dot loic at gmail dot com | Date: | Thu, 13 Aug 2015 09:13:17 +0000 |
| Subject: | note 117809 added to function.feof | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203326@lists.php.net to get a copy of this message | ||
To avoid infinite loops and the warning :
"Warning: feof() expects parameter 1 to be resource, boolean given"
You need to check that the fopen function return the correct type.
This can be achieved very easily with gettype().
Here is an example :
$source = fopen($xml_uri, "r");
$xml = "";
if(gettype($source) == "resource") { // Check here !
while (!feof($source)) {
$xml .= fgets($source, 4096);
}
}
echo $xml;
----
Server IP: 72.52.91.14
Probable Submitter: 109.211.6.105
----
Manual Page -- http://php.net/manual/en/function.feof.php
Edit -- https://master.php.net/note/edit/117809
Del: integrated -- https://master.php.net/note/delete/117809/integrated
Del: useless -- https://master.php.net/note/delete/117809/useless
Del: bad code -- https://master.php.net/note/delete/117809/bad+code
Del: spam -- https://master.php.net/note/delete/117809/spam
Del: non-english -- https://master.php.net/note/delete/117809/non-english
Del: in docs -- https://master.php.net/note/delete/117809/in+docs
Del: other reasons-- https://master.php.net/note/delete/117809
Reject -- https://master.php.net/note/reject/117809
Search -- https://master.php.net/manage/user-notes.php