0

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 ?

user1314404
  • 1,253
  • 3
  • 22
  • 51
  • 2
    You have utf-8 decode in your tags but \u1ec7 is unicode, this calls for unicode decode functions. http://stackoverflow.com/questions/2934563/ should help with that part. – Digits Mar 30 '15 at 16:30
  • I just tried but it not work. it returns exactly the same thing: Luyện – user1314404 Mar 30 '15 at 16:36
  • What you are getting after using `json_decode` _is_ UTF-8, and it _is_ `Luyện`. If you are getting something else _displayed_, that means you are outputting it into a context that does _not_ use UTF-8. – CBroe Mar 30 '15 at 18:06
  • I output it by echo and display on webpage. Do you mean html or browser does not use UTF-8? How come I still can see Vietnamese on website ? – user1314404 Mar 31 '15 at 01:44
  • @CBroe: I tried to save it to db too and the format I get is still Luyện. So it is not about display isn't it ? – user1314404 Apr 01 '15 at 07:34
  • No, it is about you not handling the character encoding correctly. – CBroe Apr 01 '15 at 11:42
  • @CBroe: So which is the correct way to handle it ? Can u post an asnwer pls, thanks ! – user1314404 Apr 02 '15 at 01:42

1 Answers1

0

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);

user1314404
  • 1,253
  • 3
  • 22
  • 51