|
Posted by Rik on 08/17/07 03:07
On Fri, 17 Aug 2007 04:40:25 +0200, Kevin Raleigh <kraleigh@sbcglobal.ne=
t> =
wrote:
> I need to read a file of names and email addresses
>
> I can use fgets() to read each line, but I am not sure
> how to use strtok($myString, "\n") to parse the
> individual elements on each line.
>
> Jon Doe myemail@aol.com
>
> tab delimited ^^
>
> what I have is a very crude attempt:
> $file =3D @fopen("test_email.txt", "r") or exit("Unable to open file!"=
);
>
> while (!feof($file)) {
> $myString =3D fgets($file, 4096);
> $token =3D strtok($myString, "\n");
>
> while ($token !=3D=3D false)
> {
> echo "$token<br/>";
> $myString =3D strtok($myString, "\n");
Well, $token doesn't get changed.. And you mixed fgets() & strtok(), not=
=
ideal.
> }
> }
> fclose($handle);
$file =3D @fopen("test_email.txt", "r") or exit("Unable to open file!");=
while($array =3D fgetcsv($file,0,"\t")) print_r($array);
//or
$file =3D @fopen("test_email.txt", "r") or exit("Unable to open file!");=
while($row =3D fgets($file,4096)){
$arr =3D explode("\t",$row);
print_r($arr);
}
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|