Re: Read first 10 lines from a file
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Read first 10 lines from a file

From: Erwin Moller <since_humans_read_this_I_am_spammed_too_much@spamyourself.com>
Date: Fri Aug 19 2005 - 17:23:27 CEST

Robertico wrote:

> I have an ASCII file with each data record on a separateline. Each field
> is delimited with a TAB (ASCII 9) character.
> Now i want to read the first 10 lines and show them on my site.
>
> This is what i already have reading the first line:
>
> $fname = "http://www.somedomain.com/file.txt";
>
> $fd = fopen($fname, "r");
> if ($fd) {
> if (!feof ($fd)) {
> $buffer = fgets($fd, 4096);
> $field = split(chr(9), trim($buffer));
> $field0 = "$field[0]";
> $field1 = "$field[1]";
> }
> fclose($fd);
> }
>
> echo ("$field0 - $field1");
>
> How can i do this voor the first 10 lines ?
>
> Regards,
>
>
> Robertico

Hi,

Look at the function name file() at www.php.net.
It reads lines into an array.
Take the first 10...

Regards,
Erwin Moller
Received on Mon Oct 24 02:09:28 2005