Parsing CSV output from Database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shortmatt
Forum Newbie
Posts: 2
Joined: Sat Jul 22, 2006 8:58 pm

Parsing CSV output from Database

Post 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!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

explode() in conjunction with file() :wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

fgetcsv() may be of interest too.
shortmatt
Forum Newbie
Posts: 2
Joined: Sat Jul 22, 2006 8:58 pm

Post 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!
Post Reply