Re: [PHP] How do I read the first n lines from a file?

2001-08-28 Thread Hugh Danaher

If the lines terminate in "\n", I'd use fgets($fp,1000) in a loop, and loop
as many times as needed.

$fp=fopen("filename","r") or die ("couldn't open filename");
for ($count=1;$count<=10,$count++)
{
$line=fgets($fp,1000);   // the 1000 represents the number of bytes to
go to unless it finds "\n" sooner.
print "$line";
}
I'm prety sure the above will work.
Hugh
- Original Message -
From: Jon Farmer <[EMAIL PROTECTED]>
To: Tauntz <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, August 28, 2001 6:40 AM
Subject: RE: [PHP] How do I read the first n lines from a file?


> If you are on a unix box you might want to use the tail command... if you
> use exec() the output will be in an array...
>
> --
> Jon Farmer  Õ?Õ?
> Systems Programmer, Entanet www.enta.net
> Tel +44 (0)1952 428969 Mob +44 (0)7968 524175
> PGP Key available, send blank email to [EMAIL PROTECTED]
>
> -Original Message-
> From: Tauntz [mailto:[EMAIL PROTECTED]]
> Sent: 28 August 2001 12:13
> To: [EMAIL PROTECTED]
> Subject: [PHP] How do I read the first n lines from a file?
>
>
> hi !
>
> I have a simmple question :)..
>
> Lets say that I have a file called:
> list.txt
> and I want to take the first 10 lines from it & echo it to the browser ?
>
> thank you
> [EMAIL PROTECTED]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] How do I read the first n lines from a file?

2001-08-28 Thread Jon Farmer

If you are on a unix box you might want to use the tail command... if you
use exec() the output will be in an array...

--
Jon Farmer  Õ?Õ?
Systems Programmer, Entanet www.enta.net
Tel +44 (0)1952 428969 Mob +44 (0)7968 524175
PGP Key available, send blank email to [EMAIL PROTECTED]

-Original Message-
From: Tauntz [mailto:[EMAIL PROTECTED]]
Sent: 28 August 2001 12:13
To: [EMAIL PROTECTED]
Subject: [PHP] How do I read the first n lines from a file?


hi !

I have a simmple question :)..

Lets say that I have a file called:
list.txt
and I want to take the first 10 lines from it & echo it to the browser ?

thank you
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] How do I read the first n lines from a file?

2001-08-28 Thread Data Driven Design

You might be better off using the file() function which reads a file into an
array, then you can use the indexes to get whatever lines you want

http://www.php.net/manual/en/function.file.php

Data Driven Design
1506 Tuscaloosa Ave
Holly Hill, Florida 32117

http://www.datadrivendesign.com
Phone: (386) 226-8979

Websites That WORK For You
- Original Message -
From: "Tauntz" <[EMAIL PROTECTED]>
To: "php" <[EMAIL PROTECTED]>
Sent: Tuesday, August 28, 2001 7:59 AM
Subject: Re: [PHP] How do I read the first n lines from a file?


> hey.. thank you..
> but is it possible to read the last lets say 10 lines from a file ?
>
>
> - Original Message -
> From: "Niklas Lampén" <[EMAIL PROTECTED]>
> To: "Tauntz" <[EMAIL PROTECTED]>; "Php-General" <[EMAIL PROTECTED]>
> Sent: Tuesday, August 28, 2001 3:28 PM
> Subject: RE: [PHP] How do I read the first n lines from a file?
>
>
> > You can do this:
> >
> > $i = 0;
> > $fp = fopen("list.txt", "r");
> > while (!feof($fp) && $i < 10) {
> > $i++;
> > $Text = fgets($fp, 4096); // Reads first 4096 characters from a row.
> > print "$Text\n";
> > };
> >
> >
> > Niklas
> >
> > -Original Message-
> > From: Tauntz [mailto:[EMAIL PROTECTED]]
> > Sent: 28. elokuuta 2001 14:13
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] How do I read the first n lines from a file?
> >
> >
> > hi !
> >
> > I have a simmple question :)..
> >
> > Lets say that I have a file called:
> > list.txt
> > and I want to take the first 10 lines from it & echo it to the browser ?
> >
> > thank you
> > [EMAIL PROTECTED]
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] How do I read the first n lines from a file?

2001-08-28 Thread Niklas Lampén

Yes. Then you have to do it a bit differently:

$file = file("list.txt"); // $file is now an array of lines in "list.txt"

for ($i = count($file); $i > count($file) - 10; $i--) {
print "$file[$i]";
};


That should do. Didn't try it thou. That prints the lines in order last,
last-1, last-2


Niklas


-Original Message-
From: Tauntz [mailto:[EMAIL PROTECTED]]
Sent: 28. elokuuta 2001 15:00
To: php
Subject: Re: [PHP] How do I read the first n lines from a file?


hey.. thank you..
but is it possible to read the last lets say 10 lines from a file ?


- Original Message -
From: "Niklas Lampén" <[EMAIL PROTECTED]>
To: "Tauntz" <[EMAIL PROTECTED]>; "Php-General" <[EMAIL PROTECTED]>
Sent: Tuesday, August 28, 2001 3:28 PM
Subject: RE: [PHP] How do I read the first n lines from a file?


> You can do this:
>
> $i = 0;
> $fp = fopen("list.txt", "r");
> while (!feof($fp) && $i < 10) {
> $i++;
> $Text = fgets($fp, 4096); // Reads first 4096 characters from a row.
> print "$Text\n";
> };
>
>
> Niklas
>
> -Original Message-
> From: Tauntz [mailto:[EMAIL PROTECTED]]
> Sent: 28. elokuuta 2001 14:13
> To: [EMAIL PROTECTED]
> Subject: [PHP] How do I read the first n lines from a file?
>
>
> hi !
>
> I have a simmple question :)..
>
> Lets say that I have a file called:
> list.txt
> and I want to take the first 10 lines from it & echo it to the browser ?
>
> thank you
> [EMAIL PROTECTED]
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] How do I read the first n lines from a file?

2001-08-28 Thread Tauntz

hey.. thank you..
but is it possible to read the last lets say 10 lines from a file ?


- Original Message -
From: "Niklas Lampén" <[EMAIL PROTECTED]>
To: "Tauntz" <[EMAIL PROTECTED]>; "Php-General" <[EMAIL PROTECTED]>
Sent: Tuesday, August 28, 2001 3:28 PM
Subject: RE: [PHP] How do I read the first n lines from a file?


> You can do this:
>
> $i = 0;
> $fp = fopen("list.txt", "r");
> while (!feof($fp) && $i < 10) {
> $i++;
> $Text = fgets($fp, 4096); // Reads first 4096 characters from a row.
> print "$Text\n";
> };
>
>
> Niklas
>
> -Original Message-
> From: Tauntz [mailto:[EMAIL PROTECTED]]
> Sent: 28. elokuuta 2001 14:13
> To: [EMAIL PROTECTED]
> Subject: [PHP] How do I read the first n lines from a file?
>
>
> hi !
>
> I have a simmple question :)..
>
> Lets say that I have a file called:
> list.txt
> and I want to take the first 10 lines from it & echo it to the browser ?
>
> thank you
> [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] How do I read the first n lines from a file?

2001-08-28 Thread Niklas Lampén

Oops.. Forgot to close the file. Put as last line:
fclose($fp);


Niklas

-Original Message-
From: Niklas Lampén [mailto:[EMAIL PROTECTED]]
Sent: 28. elokuuta 2001 15:29
To: Tauntz; Php-General
Subject: RE: [PHP] How do I read the first n lines from a file?


You can do this:

$i = 0;
$fp = fopen("list.txt", "r");
while (!feof($fp) && $i < 10) {
$i++;
$Text = fgets($fp, 4096); // Reads first 4096 characters from a row.
print "$Text\n";
};


Niklas

-Original Message-
From: Tauntz [mailto:[EMAIL PROTECTED]]
Sent: 28. elokuuta 2001 14:13
To: [EMAIL PROTECTED]
Subject: [PHP] How do I read the first n lines from a file?


hi !

I have a simmple question :)..

Lets say that I have a file called:
list.txt
and I want to take the first 10 lines from it & echo it to the browser ?

thank you
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] How do I read the first n lines from a file?

2001-08-28 Thread Niklas Lampén

You can do this:

$i = 0;
$fp = fopen("list.txt", "r");
while (!feof($fp) && $i < 10) {
$i++;
$Text = fgets($fp, 4096); // Reads first 4096 characters from a row.
print "$Text\n";
};


Niklas

-Original Message-
From: Tauntz [mailto:[EMAIL PROTECTED]]
Sent: 28. elokuuta 2001 14:13
To: [EMAIL PROTECTED]
Subject: [PHP] How do I read the first n lines from a file?


hi !

I have a simmple question :)..

Lets say that I have a file called:
list.txt
and I want to take the first 10 lines from it & echo it to the browser ?

thank you
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]