Page 1 of 1

Parsing CSV output from Database

Posted: Sat Jul 22, 2006 9:21 pm
by shortmatt
I'm trying to parse a simple CSV file from FileMaker. It looks something like this:

"matt short","matt.short@email.com","x103"
"next employee","next.employee@email.com","x104"

etc.

Is there a way to have PHP break each column out to become a variable? For instance, $name = $csv[1]

What I'm trying to do is create a web page that will list the name as a hyperlink to the email address for each employee.

<a href=mailto:$email>$name</a><br>$extension

or something to that affect. I just can't seem to find a way to have PHP break each element out to do that

Can anyone help? Thanks!

Posted: Sat Jul 22, 2006 9:42 pm
by John Cartwright
explode() in conjunction with file() :wink:

Posted: Sat Jul 22, 2006 10:23 pm
by feyd
fgetcsv() may be of interest too.

Posted: Sun Jul 23, 2006 11:10 am
by shortmatt
Got it w/ fgetcsv

$data = fgetcsv($handle, 10000, ",")

Now $data[0] is the name, $data[1] is the email and $data[2] is the phone extension.

And then I can simply display from there:

echo "<a href=mailto:$data[1]>$data[0], $data[2]</a> <br>";

Thanks fyed for your help!