note 17355 added to function.fgets
| From: | jidarNOSPAM at par1 dot net | Date: | Wed, 05 Dec 2001 17:53:49 +0000 |
| Subject: | note 17355 added to function.fgets | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21642@lists.php.net to get a copy of this message | ||
We have seen the correct way to test for feof in a few posts above:
$buffer = fgets ($fp)
while (!feof ($fp))
{
//code code.. blah
//code here..
$buffer = fgets ($fp)
}
But I have been just testing the return value of fgets:
while ($buffer = fgets ($fp))
{
// Code code...
}
Since fgets returns FALSE when no data has been read you can be certain you wont make a pass through
your logic with an empty buffer.
I haven't had any problems doing this and as far as I can tell it's a cleaner way of
handling things.
--
http://www.php.net/manual/en/function.fgets.php
http://master.php.net/manage/user-notes.php?action=edit+17355
http://master.php.net/manage/user-notes.php?action=delete+17355
http://master.php.net/manage/user-notes.php?action=reject+17355