问题
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