为什么我的Twitter推文中会出现奇怪的字符?
例如:
RT @FrankPasquale:“远离超级大国,欧共体” 官僚机构很小 - 欧盟人口为500人,有25,000人 百万“https://tâ€|
特别是 https://tâ€| - 它根本不是有效的链接/网址!
关注此guide,以下是我的代码如何从用户时间线获取Twitter推文:
$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 />";
}
任何想法为什么以及如何解决它?
修改
如果我试试这个:
htmlentities($items['text'], ENT_NOQUOTES, 'UTF-8')
我明白了:
RT @FrankPasquale:“EC的官僚机构远不是一个超级大国 对于欧盟5亿人口“https://t ... 而言,这一数字很小 - 为25,000人
链接 https://t ... 完全破碎了!
我也将我的html设置为:
<meta charset="UTF-8">
但我仍然会得到这样的链接:
https://t ...
哪个完全坏了!
编辑2:
问题来自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"
如果你看#BrexitVote\nhttps:\/\/t.c\u2026
那就是错误。
如何解决这个问题?