Newbie Question
am 19.12.2007 06:38:42 von HardySpicer
I have a text file with 6 colums of data. I need to read it and in
colums 2 and 3 do something to the data. First of all I can read the
file (all of it) or some of it ie one line
$myFile = "orbit.txt";
$fh = fopen($myFile, 'r');
$theData = fgets($fh);
fclose($fh);
echo $theData;
?>.
and this is ok. How to get to the data in colum 2 and 3 of this thing
called $theData?
Also I need to put a loop around it for i = 0 to end of file (do
something)
as in basic.
regards
Hardy
Re: Newbie Question
am 19.12.2007 13:58:20 von luiheidsgoeroe
On Wed, 19 Dec 2007 06:38:42 +0100, HardySpicer =
wrote:
> I have a text file with 6 colums of data. I need to read it and in
> colums 2 and 3 do something to the data. First of all I can read the
> file (all of it) or some of it ie one line
>
>
>
>
> $myFile =3D "orbit.txt";
> $fh =3D fopen($myFile, 'r');
> $theData =3D fgets($fh);
> fclose($fh);
> echo $theData;
>
>
> ?>.
>
> and this is ok. How to get to the data in colum 2 and 3 of this thing
> called $theData?
>
> Also I need to put a loop around it for i =3D 0 to end of file (do
> something)
> as in basic.
It all depends on how your file is formatted/how these elusive 'columns'=
=
are defined.
Probably csv, then this is something you want:
$myFile =3D 'file.csv';
$fh =3D fopen($myFile);
while($row =3D fgetcsv($fh)){
echo "
value 2: {$row[1]}
value 3: {$row[2]}":
}
?>
-- =
Rik Wasmus