views:

26

answers:

2

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 our 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?

+2  A: 

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');
Daniel Egeberg
Thanks Daniel, your answer and Peters did the job perfectly. +1
Alex
+2  A: 

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' );
Peter Bailey
Thanks a lot, I see what I was doing wrong now as the browser didn't know the format to display the characters. Another lesson learnt. I'll mark yours as the answer as you were a whole 15 seconds faster then Daniel ;)
Alex