You are here: Re: file read and strtok « PHP Language « IT news, forums, messages
Re: file read and strtok

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]


Удаленная работа для программистов  •  Как заработать на 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

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