note 13408 added to function.fgets.php
| From: | jim dot hatfield at insignia dot com | Date: | Fri, 15 Jun 2001 10:02:48 +0000 |
| Subject: | note 13408 added to function.fgets.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14354@lists.php.net to get a copy of this message | ||
It would appear that feof will not return true immediately after a file has been opened, but only
after a read attempt has been made. So Example 1 here will always return an empty buffer on the last
pass of the loop. The correct syntax is:
$fd = fopen("/tmp/inputfile.txt", "r");
$buffer = fgets($fd, 4096);
while (!feof($fd))
{
echo $buffer;
$buffer = fgets($fd, 4096);
}
fclose($fd);
http://www.php.net/manual/en/function.fgets.php