|
Posted by Stefan Rybacki on 10/10/53 11:24
Tyrone Slothrop wrote:
>...
>
> Use the file function instead:
> $lines = file('file.txt');
> for ($i=0; $i<10; $i++) {
> $field = split("\t", $lines);
> echo $f[0]]." - ".$f[1] ;
> }
>
>
Robertico keep track of the file size, when using this because the file is read at once.
Your approach is better for big files, just add a counting variable and make your if a
loop then break after 10 steps.
$fd = fopen($fname, "r");
if ($fd) {
$count=0;
while (!feof ($fd) && $count<10) {
$buffer = fgets($fd, 4096);
$field = split(chr(9), trim($buffer));
$field0 = "$field[0]";
$field1 = "$field[1]";
//... do something with $field1 and $field2
$count++;
}
fclose($fd);
}
Stefan
[Back to original message]
|