Charset with Facebook SDK

女生的网名这么多〃 提交于 2019-12-24 16:41:16

问题


I needed to work with Facebook SDK, so with some help, I wrote script that can find informations about person. But if there is diacritic in his/her name, it will be malformed, I tried to set charset in SDK files, but it doesn't help.
For example, if the name is René Beneš, it will be RenĂ© Beneš.
Can you help me please?
Thank you


回答1:


I can describe, at the character level, what is going on here – I hope it helps you closer to a solution. You apparently get the data in UTF-8 encoding, but your software interprets it as ISO-8859-2 (ISO Latin 2, “East European”) encoding. For example, letter “é” (U+00E9) is two bytes 0xC3 0xA9 in UTF-8. If the bytes are incorrectly interpreted according to ISO-8859-2, 0xC3 becomes Ă and 0xA9 becomes ©.

So you should try to make your software read and process the data in UTF-8 or to transcode it from UTF-8 to the encoding you use.




回答2:


I'm sure utf8_decode and/or utf8_encode will work great for you.




回答3:


1st Example - PHP

I suggest you to use PHP function called str_replace():

$name = 'René Beneš';

$replace = array('é','š');
$replaced = array('e','s');

// output = Rene Benes
echo str_replace($replace, $replaced, $name);

You can find more about that function on official PHP website - str_replace().

Furthermore, more informations and HTML codes about special characters are available on Special Characters in HTML.

2nd Example - HTML

Try to replace:

<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" />

between your <head></head> section.



来源:https://stackoverflow.com/questions/9149916/charset-with-facebook-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!