note 61207 deleted from function.fseek by nlopess
| From: | nlopess@php.net | Date: | Sat, 28 Jan 2006 10:56:22 +0000 |
| Subject: | note 61207 deleted from function.fseek by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-102608@lists.php.net to get a copy of this message | ||
Note Submitter: mno2go [a] gmail.com
----
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;
}