You need to convert your string to UTF8 also.
utf8_encode() does not check what encoding your string was in, and sometimes it gives you a messed up string, so I made a function called forceUTF8() to do this right.
You dont need to know what the encoding of your strings is. It can be Latin1 (iso 8859-1) or UTF8, or the string can have a mix of the two. forceUTF8() will convert everything to UTF8.
I needed this because a service was giving me a data feed all messed up, mixing UTF8 and Latin1 in the same string.
Usage:
$utf8_string = forceUTF8($utf8_or_latin1_or_mixed_string);
$latin1_string = forceLatin1($utf8_or_latin1_or_mixed_string);
I've included another function, fixUFT8(), wich will fix every UTF8 string that looks garbled.
Usage:
$utf8_string = fixUTF8($garbled_utf8_string);
Examples:
echo fixUTF8("Fédération Camerounaise de Football");
echo fixUTF8("Fédération Camerounaise de Football");
echo fixUTF8("FÃÂédÃÂération Camerounaise de Football");
echo fixUTF8("Fédération Camerounaise de Football");
will output:
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Download:
http://dl.dropbox.com/u/186012/PHP/forceUTF8.zip