Possibly a very simple question , but I 开发者_JS百科was wondering how I can decode utf8 characters into readable characters.
For example :
L'heure suprême
Into
L'heure suprême
I tried the following :
utf8_encode , utf8_decode And `html_entity_decode($string, ENT_COMPAT, "UTF-8");`
The output never gave me the correct characters , for example
html_entity_decode($string, ENT_COMPAT, "UTF-8"); returned L'heure suprême
EDIT :
It was a stupid question , html_entity_decode($string, ENT_COMPAT, "ISO-8859-15");
did the trick
In order for your results to be properly displayed, you'll need to tell the receiving end, which encoding is used:
header('Content-Type: text/plain; charset=UTF-8');
$string = 'L'heure suprême';
print html_entity_decode($string, ENT_COMPAT, "UTF-8");
The output without explicitly naming a charset encoding provokes undefined behavior. Earlier today, someone suggested a great article by Joel Spolsky on Unicode and Character sets. It makes for a good read and I'll suggest you "skim over" it.
精彩评论