Twitter json API foreign characters
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 ��.
In the json file the two question marks are \u00d6.
I'm using this script to get the json and decode it: http://pastebin.com/X3pjKrSi
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?
The same characters works fine in the rest of the site (built in Wordpress).
Thanks
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");
At the beginning of your PHP code.
精彩评论