You are here: Re: Read first 10 lines from a file « All PHP « IT news, forums, messages
Re: Read first 10 lines from a file

Posted by Tyrone Slothrop on 09/30/57 11:24

On Fri, 19 Aug 2005 12:50:34 +0200, "Robertico"
<Robertico@nomail.notvalid> 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 ?

Use the file function instead:
$lines = file('file.txt');
for ($i=0; $i<10; $i++) {
$field = split("\t", $lines);
echo $f[0]]." - ".$f[1] ;
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация