title: UTF-8 htmlentities and fgetcsv
body: <p>I am having issues converting my special characters to htmlentities after importing my csv file.</p>
  
  <p>Here's the revelant code:</p>
  
  <pre><code>setlocale(LC_ALL, 'fr_FR.utf8');
  
  if (empty($errors) &amp;&amp; ($handle = fopen($_FILES["file"]["tmp_name"], "r")) !== FALSE) {
      $data = array();
      while (($rawdata = fgetcsv($handle, 0, $_POST["delimiter"])) !== FALSE) {
           for ($i=0; $i &lt; count($rawdata); $i++) {
                $data[$i][] = htmlentities(trim($rawdata[$i]), ENT_QUOTES, "UTF-8");
           }
      }
      fclose($handle);
  }
  </code></pre>
  
  <p>What happens though, is that any cells with a special character in it (such as ™) simply get removed / return as empty.</p>
  
  <p>I'm using PHP version 5.3.13</p>
  
  <p>I have tried setting my <code>locale</code> and tried <code>putenv</code>, but this doesn't change anything. I have also tried setting my machine's locale settings before making the csv. The csv itself is created from an Excel file. </p>
  
  <p>I have checked my csv encoding, and it seems correctly to be UTF-8 without BOM (checked in Notepad++). <code>mb_detect_encoding()</code> also returns <code>UTF-8</code>.</p>
  
  <p>When I change to <code>ENT_IGNORE</code>, it simply strips the <code>TM</code> symbol from my string. I have tried different encoding types such as <code>ISO-8859-15</code> with no avail.</p>
  
  <p><code>str_replace("™", "%99", $row)</code> just ignores the <code>TM</code> symbols and leaves them how they were.</p>
  
  <p>I've found that a lot of people have issues with <code>fgetcsv()</code> and encoding / special characters, and most of them refer to using a different method such as <code>fgets()</code>. Unfortunately I haven't been able to get those other methods to work either because I cannot explode on newline since some of the cells may include newlines in their content.
  I will accept a different method as answer as well if I can get it to work.</p>