Working with files and utf8 in PHP

furcal15

New Member
This is driving me crazy.Lets say I have a file called foo.txt encoded in utf8:\[code\]aoeu qjkx?pyf\[/code\]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.I wrote the following code (also encoded as utf8):\[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\]However, after that, the \[code\]$lines\[/code\] array just has the aoeu line in it.
This seems to be because somehow, the "?" in \[code\]$allowed_letters\[/code\] is not the same as the "?" in foo.txt.
Also if I print a "?" of the file, a question mark appears, but if I print it like this \[code\]print "?";\[/code\], it works.
How can I make it work?
 
Back
Top