Why do I get strange characters in my twitter tweets?
For example:
RT @FrankPasquale: “Far from being a superstate, the EC’s bureaucracy is tiny--25,000 people for an EU population of 500 million" https://t…
Especially https://t… - it is not a valid link/ url at all!
Follow this guide, below is my code how I get the twitter tweet from an user timeline:
$settings = array(
'oauth_access_token' => "xxx",
'oauth_access_token_secret' => "xxx",
'consumer_key' => "xxx",
'consumer_secret' => "xxx"
);
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$requestMethod = "GET";
$getfield = '?screen_name=xxxx&count=6';
$string = json_decode(
$twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(), $assoc = TRUE
);
if (isset($string["errors"]) && $string["errors"][0]["message"] != "") {
echo "<h3>Sorry, there was a problem.</h3>
<p>Twitter returned the following error message:</p>
<p><em>" . $string[errors][0]["message"] . "</em></p>";
exit();
}
foreach($string as $items) {
echo "Time and Date of Tweet: ".$items['created_at']."<br />";
echo "Tweet: ". $items['text']."<br />";
echo "Tweeted by: ". $items['user']['name']."<br />";
echo "Screen name: ". $items['user']['screen_name']."<br />";
echo "Followers: ". $items['user']['followers_count']."<br />";
echo "Friends: ". $items['user']['friends_count']."<br />";
echo "Listed: ". $items['user']['listed_count']."<br /><br />";
}
Any ideas why and how I can fix it?
EDIT:
If I try this:
htmlentities($items['text'], ENT_NOQUOTES, 'UTF-8')
I get this:
RT @FrankPasquale: “Far from being a superstate, the EC’s bureaucracy is tiny--25,000 people for an EU population of 500 million" https://t…
The link https://t… is totally broken!
I also have set my html to:
<meta charset="UTF-8">
But I still get this kind of links:
Which is totally broken!
EDIT 2:
The problem is coming from twitter json:
{"created_at":"Fri Jun 24 14:28:16 +0000 2016","id":xxx,"id_str":"xxxx","text":"RT @muslimgirl: The people who invaded & colonized the world decided they wanted independence from its consequences
#BrexitVote\nhttps:\/\/t.c\u2026"
If you look at #BrexitVote\nhttps:\/\/t.c\u2026
that is the bug.
How can fix that?