note 15515 deleted from function.fgets by sniper
| From: | sniper@php.net | Date: | Sat, 08 Feb 2003 20:09:21 +0000 |
| Subject: | note 15515 deleted from function.fgets by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43659@lists.php.net to get a copy of this message | ||
The given example for reading a file is incorrect. It will introduce an
additional run through the loop, since once the last byte has been
read of a text file (terminating say in \n), the feof does not yet indicate
end of file - you have to read PAST it.
The correct code structure looks more like this:
$fd = fopen ("/tmp/inputfile.txt", "r");
$buffer = fgets($fd, 4096);
while (!feof ($fd)) {
echo $buffer;
$buffer = fgets($fd, 4096);
}
fclose ($fd);