title: small glitch while generating csv with newline character in php
body: <p>I am simply generating a csv file based on data stored in a mysql table. The generated csv, when opened in excel, seems mostly ok, but whenever it has a newline character, excel puts the data on a new row. Any idea how to prevent that?</p>
  
  <p>Sample data</p>
  
  <pre><code>line 1 some data
  another data
  </code></pre>
  
  <p>CSV generation code:</p>
  
  <pre><code>header("Content-Type: text/csv; charset=UTF-8");
  header("Content-Disposition: attachment; filename=\"".$MyFileName."\"");
  $filename = $MyFileName;
  $handle = fopen("temp_files/".$filename, "r");
  $contents = fread($handle, filesize("temp_files/".$filename));
  fclose($handle);
  echo $contents;  
  exit;
  </code></pre>
  
  <p>content snippet I used to get rid of new line(didn't work):</p>
  
  <pre><code>$pack_inst = str_replace(',',' ',$get_data-&gt;fields['pack_instruction']);
          $pack_inst = str_replace('\n',' ',$pack_inst);
          $pack_inst = str_replace('\r',' ',$pack_inst);
          $pack_inst = str_replace('\r\n',' ',$pack_inst);
          $pack_inst = str_replace('&lt;br&gt;',' ',$pack_inst);
          $pack_inst = str_replace('&lt;br/&gt;',' ',$pack_inst);
          $pack_inst = str_replace(PHP_EOL, '', $pack_inst);
          $pattern = '(?:[ \t\n\r\x0B\x00\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}]|&amp;nbsp;|&lt;br\s*\/?&gt;)+';
          $pack_inst = preg_replace('/^' . $pattern . '|' . $pattern . '$/u', ' ', $pack_inst);
          $content .=','.$pack_inst;
  </code></pre>