I'm trying to post special characters to facebook feed, but the characters shown in the facebook post doesn't show as I intended.
$tmp = "αвнιjτυz";
//This code works as I intended, showing "αвнιjτυz" on facebook post
$facebook->api('/me/feed', 'POST', array('message' => $tmp));
//I expe开发者_开发知识库ct the displayed text in facebook post will be 'вн' but it shows strange characters instead
$facebook->api('/me/feed', 'POST', array('message' => substr($tmp, 1, 2)));
Any ideas why this happens and how to tackle this problem?
I'm guessing this is unicode that you're working in. If so substr()
won't work with unicode characters as they're represented with multiple bytes, you will need to use the mb_substr()
function instead.
$facebook->api('/me/feed', 'POST', array('message' => mb_substr($tmp, 1, 2)));
This is an old question, but missing the follow-up to Martin's question (and solution to question).
You should set the Content-Type of both the html and php to UTF-8. So at the beginning of the php code:
header('Content-Type: text/html; charset=utf-8');
And with the html:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
精彩评论