note 61207 added to function.fseek
| From: | mno2go | Date: | Sat, 28 Jan 2006 05:08:01 +0000 |
| Subject: | note 61207 added to function.fseek | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102599@lists.php.net to get a copy of this message | ||
Easier, and possibly faster ways of going to a certain line number and finding the number of lines
in a file. Of course, disadvantage if PHP doesn't properly recognize the line endings.
Go to line number. It will leave off the $fp just at the line you want to go to.
function seekLine($linenumber, $fp)
{
for ($i=0; $i<$linenumber; $i++)
{
fgets($fp,4096);
}
}
Count the number of lines. Helpfully rewinds the $fp.
function countNumLines($fp)
{
$i = 0;
while (!feof($fp))
{
fgets($fp,4096);
$i++;
}
rewind($fp);
return $i;
}
----
Server IP: 195.221.21.36
Probable Submitter: 81.65.105.220
----
Manual Page -- http://www.php.net/manual/en/function.fseek.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61207
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61207&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61207&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61207&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61207&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61207&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61207&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61207&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61207&report=yes
Search -- http://master.php.net/manage/user-notes.php