RE: [PHP] Lines
| From: | Jason Murray | Date: | Wed, 25 Apr 2001 07:52:01 +0000 |
| Subject: | RE: [PHP] Lines | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-50251@lists.php.net to get a copy of this message | ||
> > it's my first post on this list, and my doubt is...
> >
> > how can i take a file.txt and
> >
> > 1 - know how many lines i have in this text
> > 2 - print line 5 until 10
> Is there any chance for you to use a database?
> these thing would become MUCH, MUCH easier.
Actually, this is really easy without using a database.
1. <?
$filename = "/path/to/file";
$filedata = file($filename);
$linesinfile = count($filedata);
?>
2. <?
$startline = 5;
$stopline = 10;
for ($i = $startline; $i < $stopline; $i++ )
{
echo $filedata[$i-1];
}
?>
(Use $i-1 because the first line is actually "0").
Jason