title: Replacing or Removing a new line with something else but only between single or double quotes using PHP on a CSV file
body: <p>I have a CSV file that holds about 200,000 - 300,000 records. Most of the records can be separated and inserted into a MySQL database with a simple </p>
  
  <pre><code>$line = explode("\n", $fileData);
  </code></pre>
  
  <p>and then the values separated with</p>
  
  <pre><code>$lineValues = explode(',', $line);
  </code></pre>
  
  <p>and then inserted into the database using the proper data type i.e int, float, string, text, etc.</p>
  
  <p>However, some of the records have a text column that includes a \n in the string. Which breaks when using the $line = explode("\n", $fileData); method. Each line of data that needs to be inserted into the database has approximately 216 columns. not every line has a record with a \n in the string. However, each time a \n is found in the line it is enclosed between a pair of single quotes (')</p>
  
  <p>each line is set up in the following format:</p>
  
  <pre><code>id,data,data,data,text,more data
  </code></pre>
  
  <p>example:</p>
  
  <pre><code>1,0,0,0,'Hello World,0
  2,0,0,0,'Hello
      World',0
  3,0,0,0,'Hi',0
  4,0,0,0,,0
  </code></pre>
  
  <p>As you can see from the example, most records can be easily split with the methods shown above. Its the second record in the example that causes the problem.</p>
  
  <p>New lines are only \n and the file does not include \r in the file at all.</p>