Connecting Tech Pros Worldwide Help | Site Map

How to parse a CSV that contains commas

gregerly's Avatar
Expert
 
Join Date: Sep 2006
Posts: 189
#1: Sep 24 '08
I'm having an issue parsing a CSV file in which some fields contain commas. My CSV looks something like this:

Expand|Select|Wrap|Line Numbers
  1. 123,asdflkj23klj,"Sept. 22, 2008",some field,one more field,"Aug 1,1983"
To parse my csv files I was reading it into an array with file(), and then looping the lines, exploding by comma, IE explode(',',$line), however this doesn't work as it will explode the commas in the date fields.

I guess my main question is how do I parse a CSV which may or may not contain comma's in some of the fields.

Thanks!
MarkoKlacar's Avatar
Expert
 
Join Date: Aug 2007
Location: Stockholm, Sweden
Posts: 294
#2: Sep 24 '08

re: How to parse a CSV that contains commas


Hi,

Have a look at the string tokenizer.

Good luck...

/MK
Newbie
 
Join Date: Mar 2007
Posts: 31
#3: Sep 24 '08

re: How to parse a CSV that contains commas


hi,
have a look at fgetcsv

regards
nelluru
Reply