title: Escaping a comma when uploading a .csv to a database with PHP
body: <p>I'm trying to do a simple PHP function to put a .csv file into a database. The problem is that the files are delimited with a semicolon and for some reason when a cell contains a comma it leaves out everything after it.</p>
  
  <p>For example the .csv file</p>
  
  <pre><code>manufacturer;comment;year
  toyota;good car, bad color;1997
  </code></pre>
  
  <p>comes out as the following when printed with the <code>print_r()</code> function</p>
  
  <pre><code>[0] =&gt; Array
  (
      [0] =&gt; manufacturer
      [1] =&gt; comment
      [2] =&gt; year
  )
  
  [1] =&gt; Array
  (
      [0] =&gt; toyota
      [1] =&gt; good car
  )
  </code></pre>
  
  <h3>Edit</h3>
  
  <p>Here's the code I'm using. </p>
  
  <pre><code>//get the contents of the .csv file     
  $filepath = './files/csvfile.csv'
  $fileopen = fopen($filepath,"r");
  //create an empty array
  $csv = array();
  //go through the .csv file with fgetcsv()
  while(($line = fgetcsv($fileopen,";")) !== FALSE)
  {
  
      $line =  explode(";",$line[0]);
  
  
      $csv[] = $line;
  }
  
      //print the result
      echo "&lt;pre&gt;";
              print_r($csv);
      echo "&lt;/pre&gt;";
  fclose($fileopen);
  </code></pre>