Good day,
I create me a little class that give out the latest Tweets from my Account, but when I testing it, all the special characters are like “Ã�”.
The problem is, all my pages use UTF-8 but the data I recived from Twitter do this not.
Here is the example class from my Twitter Script:
<?php
function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = “$key=” . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . ‘&’ . rawurlencode(implode(’&’, $r));
}
function buildAuthorizationHeader($oauth) {
$r = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(', ', $values);
return $r;
}
$url = “https://api.twitter.com/1.1/statuses/user_timeline.json”;
$oauth_access_token = “”;
$oauth_access_token_secret = “”;
$consumer_key = “”;
$consumer_secret = “”;
$query = array(
‘count’ => ‘5’
);
$oauth = array(
‘oauth_consumer_key’ => $consumer_key,
‘oauth_nonce’ => time(),
‘oauth_signature_method’ => ‘HMAC-SHA1’,
‘oauth_token’ => $oauth_access_token,
‘oauth_timestamp’ => time(),
‘oauth_version’ => ‘1.0’
);
$base_info = buildBaseString($url, ‘GET’, $oauth, $query);
$composite_key = rawurlencode($consumer_secret) . ‘&’ . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac(‘sha1’, $base_info, $composite_key, true));
$oauth[‘oauth_signature’] = $oauth_signature;
// Make Requests
$header = array(buildAuthorizationHeader($oauth), ‘Expect:’);
$options = array( CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json, true);
for ($x = 0; $x < $query[‘count’]; ++$x)
{
$tweet = htmlentities($twitter_data[$x][‘text’]);
$tweet = preg_replace(’/(\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~|!:,.;]*[-A-Z0-9+&@#/%=~|])/i’, ’ $1’, $tweet);
$tweet = preg_replace(’/(^|\s)@([a-z0-9_]+)/i’, ’ @$2’, $tweet);
$tweet = preg_replace(’/#([a-z0-9]+)/i’, ’ #$1’, $tweet);
echo $tweet . ‘
’;
}
?>
Can anyone help me to convert the output to UTF-8?