utf 8 characters problem
Posted: Sat Oct 17, 2009 6:28 pm
i'm new to this forum so i'm sorry if this topic is discussed before, i can't find it (i'll ask the administrators to move this post to the right place if it's misplaced )
Anyway i'm trying to read from .txt file witch contains utf 8 encoded strings,each single one in a row, enter, then the others till the end with "enters" between them. Then i'm trying to get the last character from each string and if it's equal to some other character, then i like it to echo that string. But there seems to be a problem in the comparing and my "if" is not working properly. I guess there are same extra invisible characters added because of the encoding. Here is the code:
When i echo $tmp it shows me "?", but when i compare it in "if" it doesn't work as i want. Any idea why php is not handling the encoding as it should. Are the "enters" problem? Are the bytes in the encoding problem?
Thanks for the answer in advance...
Anyway i'm trying to read from .txt file witch contains utf 8 encoded strings,each single one in a row, enter, then the others till the end with "enters" between them. Then i'm trying to get the last character from each string and if it's equal to some other character, then i like it to echo that string. But there seems to be a problem in the comparing and my "if" is not working properly. I guess there are same extra invisible characters added because of the encoding. Here is the code:
Code: Select all
$tekst=fopen("text.txt","r");
while(!feof($tekst)):
$str=fgets($tekst);
$tmp1=UTF8::strlen($str); //gets the length of a string
$tmp=UTF8::substr($str, $tmp1-3, $tmp1-2); //gets the last character of the string
if ($tmp == "?"){
echo $str;
}
endwhile;
fclose($tekst);
When i echo $tmp it shows me "?", but when i compare it in "if" it doesn't work as i want. Any idea why php is not handling the encoding as it should. Are the "enters" problem? Are the bytes in the encoding problem?
Thanks for the answer in advance...