RE: [PHP] getting fields out of a csv file
| From: | Boget, Chris | Date: | Mon, 24 Jul 2000 20:23:08 +0000 |
| Subject: | RE: [PHP] getting fields out of a csv file | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-7963@lists.php.net to get a copy of this message | ||
> > Try something like this:
> > $fd = fopen ("/tmp/inputfile.txt", "r");
> > $count = 0;
> > while (!feof($fd))
> > {
> > $stuff = fgets($fd, 4096);
> > $data[$count] = explode(",", $stuff);
> > $count++;
> > }
> > fclose ($fd);
> >
> > This would give you a multi-dimensional array of all your
> > data indexed by
> > count and the number of colums.
> Thanks, this works great.
Be *very* careful with the above suggestion. If you have a string
like this:
1, "Joe Bob", "Hey, This is my favorite language", 28, 1976
You are screwed because the 3rd element ( "Hey, This is my favorite
language" ) will get turned into the 3rd and the 4th elements containgin
"Hey" and "This is my favorite language", respectively.
> Now I'm wondering how to sort on
> one of the fields (happens to be a date). It is the fourth field,
> so I'm trying somehow to sort on $data[any][4]
> Any suggestions?
I don't believe you can do this...
Chris