问题描述
我正在将Twitter json API与PHP结合使用,以在网站上显示推文.我现在注意到,如果该推文中包含诸如Ö之类的外来字符,则它会显示在站点 上.
I'm using the Twitter json API with PHP to show tweets on a website. I've now noticed that if the tweet contains a foreign character such as Ö then this shows up on the site ��.
在json文件中,两个问号是\ u00d6.
In the json file the two question marks are \u00d6.
我正在使用此脚本获取json并将其解码: http://pastebin.com/X3pjKrSi
I'm using this script to get the json and decode it: http://pastebin.com/X3pjKrSi
然后我使用jQuery ajax将其放在网站上
Then I'm using jQuery ajax to put it on the site with
$(document).ready(function(){
$.ajax({
url: '<?php bloginfo('template_url'); ?>/functions/twitter/twitter.php',
contentType: "application/json; charset=utf-8",
data: "tweets=<?php echo $options['ct_tweets']; ?>&account=<?php echo $options['ct_twitter']; ?>",
success: function(data) {
$('#twitter-loader').remove();
$('#twitter-container').html(data);
}
});
});
有人知道我要显示外国字符吗?
Does anyone know what I would have to do to display the foreign characters?
在网站的其余部分(内置于Wordpress中),相同的字符也可以正常工作.
The same characters works fine in the rest of the site (built in Wordpress).
谢谢
推荐答案
您需要通知浏览器,您将输出UTF-8内容.您可以通过添加以下内容来做到这一点:
You need to inform the browser you will be outputting UTF-8 content. You can do this by adding:
header("Content-Type:text/html; charset=UTF-8");
在PHP代码的开头.
这篇关于Twitter json API外来字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!