开发者

Character encoding problem from Facebook JSON to HTML via PHP

I'm getting a JSON encoded array from Facebook which contains:

[{"message":"D\u011bkujeme Zuzana Boh\u00e1\u010dov\u00e1 za na\u0161i novou profilovou fotku :-)\nWe thank Zuzana Boh\u00e1\u010dov\u00e1 for o开发者_如何学JAVAur new profile picture :-)"}]

When I decode the JSON and output the contents I get:

DÄ›kujeme Zuzana BoháÄová za naÅ¡i novou profilovou fotku :-) We thank Zuzana BoháÄová for our new profile picture :-)

I used mb_detect_encoding($message) and it's in utf-8 format but how do I convert the characters ready for human consumption?


You are getting all the correct bytes, but are displaying them incorrectly.

Make sure you are using the correct charset in your content-type header. The easiest way to do this in PHP is like so

ini_set( 'default_charset', 'UTF-8' );

But you are also welcome to do this

header( 'Content-Type: text/html; charset=utf-8' );


PHP decodes that just fine. When outputting it to the browser, make sure you do something like this so you don't mix character sets in your application:

header('Content-type: text/html; charset=utf-8');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜