tags:

views:

37

answers:

2

I have text in this format les validations d'entr\u00e9es instead of les validations d'entrées.

This is from Twitter .json API and I would like to translate the \u00e9 to the é but can't find a way to do it.

I suppose it's unicode so how can I translate those characters in PHP?

Sample of code that I already have:

 $this->jsonArray = json_decode($this->jsonData, true);
 //... Loop ...
 $output .=' <li class="twit">'.$this->jsonArray[$x]['text'] //....
+1  A: 

Use json_decode:

$raw = "{\"data\":\"les validations d'entr\u00e9es\"}"; var_dump(json_decode($raw));

Result:

object(stdClass)[2] public 'data' => string 'les validations d'entrées' (length=26)

Eric Butera
I already have : $this->jsonArray = json_decode($this->jsonData, true);
Daok
A: 

Alright, I thought it was Unicode but it was UTF8... Using the PHP method utf8_decode solve the problem. Thank you Eric to point me out the json_decode but it seems that it requires to have something more.

Daok
You can also convert the \uxxxxx references to HTML entities: `é` works too, but I don't entirely understand the logic behind it (which character set does this refer to?)
Pekka
If you're getting mangled characters then there is an encoding issue. The json_* functions work with utf8 data. If you are expecting some other encoding then yes, you'll have to use something such as utf8_decode like you posted. If you can, try moving towards a more progressive unicode environment. There is a lot of info on this, so I won't repeat it here. If you cannot do this I would recommend at a minimum using iconv with transliteration.
Eric Butera
Thank Eric for the comment. I will accept your answer to give you some reputation. Thanks
Daok