Search code examples
phpjsonfacebookutf8-decode

How to understand Json_decode and covert it to save-able format for database


When I get facebook login token and send it to graph link, it will return a json string, in which I find this type of format:

Luy\u1ec7n

I don't understand how facebook encode it but how it appears on facebook page actually (Vietnamese) is:

Luyện

Then I use:

$array = json_decode($data, true);

It becomes: Luyện

How could I change it to the original word Luyện ? and save it to my database ? and then, is it right way to save name to database then later query from database for other checking purposes ?


Solution

  • I found the answer: Just need to put this into my php code: header('Content-Type: text/html; charset=utf-8'); then it will display correctly. To save it on DB and display correctly in DB, need to tell the DB also: $this->link = mysql_connect($host, $user, $pass);mysql_set_charset('utf8', $this->link);