title: Dealing with commas in CSV
body: <p>I get a CSV data from a SOAP call in php. Unfortunately, the data may have commas in it. It is formatted correctly as in</p>
  
  <p>1,name,2,lariat,3,"first, last",5,NMEA,...</p>
  
  <p>I need to parse it to individual values in either php or javascript. I have browsed through threads on stack overflow and elsewhere but have not found a specific solution in php / javascript.</p>
  
  <p>The approach I am currently using is </p>
  
  <pre><code>$subject = '123,name,456,lryyrt,123213,"first,last",8585,namea3';
  $pattern = '/,|,"/';
  $t2=preg_replace ('/,|(".*")/','$0*',$subject);
  $t2=str_replace(',','*',$t2);
  $t2=str_replace('*',',',$t2);
  </code></pre>
  
  <p>Where * is the deliminator, but the <code>preg_replace</code> generates an extra *. I have tried a couple of other approaches involving <code>preg_match</code> and other <code>preg_</code> functions but did not succeed in having any kind of a clean split.</p>
  
  <p>Any suggestion on how to split up CSV data that contains commas in it?</p>