Search code examples
phpcsvtext-parsingdouble-quotesdelimited

Parse comma-separated string where some substrings are wrapped in double quotes


Trying to parse a csv file that has all the data wrapped in double quotes, because there may be commas in the double quotes.

Looks like this:

$songs = '"1, 2, 3, 4 (I Love You)","Plain White T's","CBE10-22",15,"CBE10-22","","","CB",984,"","10/05/10"';

$regResult = preg_match( "", $songs, $matches );

I can't figure out a regex that will return the data between the quotes as the matches. I'm sure there is some regex master that can help me with this.


Solution

  • you dont need no stinkin regex to parse a csv file in php.

    see fgetcsv() and str_getcsv()