Tetrax
Tetrax

Reputation: 65

How to programmatically post extended ascii character to facebook post?

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 expect 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?

Upvotes: 0

Views: 1030

Answers (2)

taylor.kelly
taylor.kelly

Reputation: 11

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">

Upvotes: 1

James C
James C

Reputation: 14159

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)));

Upvotes: 1

Related Questions