title: php fgetcsv - charset encoding problems
body: <p>Using PHP 5.3 <code>fgetcsv</code> function, I am experiencing some problems due to encoding matters. Note that that file has spanish "special" latin characters like graphic accents á, é, í ï, etc...</p>
  
  <p>I get the CSV file exporting some structured data I have in an MS 2008 for Mac Excel file.</p>
  
  <p>If I open it with Mac OS X <code>TextEdit</code> application, everything seems to go perfect.</p>
  
  <p>But when I get down to my PHP program and try to read the CSV using that fgetcsv PHP function, I am not getting it to read properly the charset.</p>
  
  <pre><code>/**
   * @Route("/cvsLoad", name="_csv_load")
   * @Template()
   */
  public function cvsLoadAction(){
      //setlocale(LC_ALL, 'es_ES.UTF-8');
      $reader = new Reader($this-&gt;get('kernel')-&gt;getRootDir().'/../web/uploads/documents/question_images/2/41/masiva.csv');
  
      $i = 1;
      $r = array("hhh" =&gt; $reader -&gt; getAll());
  
      return new Response(json_encode($r, 200));
  }
  </code></pre>
  
  <p>As you can see, I have tried also to use a <code>setlocale</code> to <code>es_ES.UTF-8</code>. But nothing get it working.</p>
  
  <p>The read part comes here:</p>
  
  <pre><code>public function getRow()
  {
      if (($row = fgetcsv($this-&gt;_handle, 10000, $this-&gt;_delimiter)) !== false) {
          $this-&gt;_line++;
          return $this-&gt;_headers ? array_combine($this-&gt;_headers, $row) : $row;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>See what I get in the $row variable after each row reading:</p>
  
  <p><img src="https://i.stack.imgur.com/jmq4L.png" alt="enter image description here"></p>
  
  <p>Those <code>?</code> characters are supposed to be vowels with graphic accents on them.</p>
  
  <p>Any clue over there? Would it work if I used MS Excel for Windows? How can I know in run time the exact encoding of the file and set it before reading it?</p>
  
  <p>(For those spanish speakers, don't get frightened with such awful medical stuff in those texts ;)).</p>