RE: [PHP] Lines
| From: | Maxim Maletsky | Date: | Wed, 25 Apr 2001 07:57:52 +0000 |
| Subject: | RE: [PHP] Lines | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-50252@lists.php.net to get a copy of this message | ||
I know, it was already answered before me (you),
I just though that an SQL database is a good advice for these who are trying
to do this kind of jobs.
It is obvious that the reason to use this function is to manage a stored
data in files.
then why not a database, if possible?
Sincerely,
Maxim Maletsky
Founder, Chief Developer
PHPBeginner.com (Where PHP Begins)
maxim@phpbeginner.com
www.phpbeginner.com
-----Original Message-----
From: Jason Murray [mailto:Jason.Murray@melbourneit.com.au]
Sent: Wednesday, April 25, 2001 4:52 PM
To: Maxim Maletsky; 'Rafael Faria'; php-general@lists.php.net
Subject: RE: [PHP] Lines
> > 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