title: Working with files and utf8 in PHP
body: <p>Lets say I have a file called foo.txt encoded in utf8:</p>
  
  <pre><code>aoeu  
  qjkx
  ñpyf
  </code></pre>
  
  <p>And I want to get an array that contains all the lines in that file (one line per index) that have the letters aoeuñpyf, and only the lines with these letters.</p>
  
  <p>I wrote the following code (also encoded as utf8):</p>
  
  <pre><code>$allowed_letters=array("a","o","e","u","ñ","p","y","f");
  
  $lines=array();
  $f=fopen("foo.txt","r");
  while(!feof($f)){
      $line=fgets($f);
      foreach(preg_split("//",$line,-1,PREG_SPLIT_NO_EMPTY) as $letter){
          if(!in_array($letter,$allowed_letters)){
              $line="";
          }
      }
      if($line!=""){
          $lines[]=$line;
      }
  }
  fclose($f);
  </code></pre>
  
  <p>However, after that, the <code>$lines</code> array just has the aoeu line in it.<br>
  This seems to be because somehow, the "ñ" in <code>$allowed_letters</code> is not the same as the "ñ" in foo.txt.<br>
  Also if I print a "ñ" of the file, a question mark appears, but if I print it like this <code>print "ñ";</code>, it works.<br>
  How can I make it work?</p>