How to parse a CSV that contains commas

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gregerly
    Recognized Expert New Member
    • Sep 2006
    • 192

    How to parse a CSV that contains commas

    I'm having an issue parsing a CSV file in which some fields contain commas. My CSV looks something like this:

    Code:
    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(',',$li ne), 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
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    Have a look at the string tokenizer.

    Good luck...

    /MK

    Comment

    • Nelluru
      New Member
      • Mar 2007
      • 31

      #3
      hi,
      have a look at fgetcsv

      regards
      nelluru

      Comment

      Working...