title: Escape special characters for fputcsv();
body: <p>Is there an easy way to escape special characters, double quotes and multiple spaces for <strong>fputcsv()</strong>? In short with a lot of regex i get data from a PDF and i build my array. Inside the array there are no html tags with the exception of <strong>&lt;br&gt;</strong> tag. Now the problem is that i have to escape chars like these:</p>
  
  <pre><code>Èàèìòù"\'       &lt;br&gt;
  </code></pre>
  
  <p>This is the messy output that i have now:</p>
  
  <pre><code>&amp;lt;br&amp;gt; instead of &lt;br&gt;
  � instead of È, ò, à, ', "
  Lot of ������� where there are multiple spaces which i don't want
  </code></pre>
  
  <p>I'm using this code:</p>
  
  <pre><code>$fichier = 'file.csv';
  header("Content-Type: text/csv;charset=UTF-8" );
  header("Content-Disposition: attachment;filename=\"$fichier\"" );
  header("Pragma: no-cache");
  header("Expires: 0");
  
  $fp= fopen('php://output', 'w');
  
  foreach ($output as $fields)
  {
      fputcsv($fp, $fields);
  }
  fclose($fp);
  exit();
  </code></pre>
  
  <p>Tryed with array_map and many other functions with no success. I'm sure that it should be a simple question of charset encoding but it seems that content type UTF-8 is not working at all.</p>