I am trying to write a regex that will allow me to parse CSV files that excel creates. I have noticed when you export a CSV from excel, if the field is a string it will encase it in quotes. If that string contains quotes itself, it will escape each quote with a quote!!

What I want to do is split each line that I parse into fields. In light of the above, I have to split when there is a comma that is not within quotes. My regex is terrible, so how would I do this?

I can split by a comma, but how do I say when its not in between quotes??

```
$lines = file($toce_path);

foreach ($lines as $line) {

    $line_array = preg_split("/,/", $line);

    $test = "($line_array[0], $line_array[1], $line_array[2])";

    echo $test.'<br />';

} 

```

[This question](https://stackoverflow.com/questions/1757065/java-splitting-a-comma-separated-string-but-ignoring-commas-in-quotes) is exactly like mine but it doesn't work with preg\_split. Preg\_split requires Perl-compatible regular expression syntax.

Thanks all for any help