我正在尝试计算某个单词在Twitter结果中的使用次数,但到目前为止,以下内容不起作用:
$recentTweets = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=username');
echo substr_count($recentTweets), 'the');
如果我使用:
$number = substr_count(strip_tags($recentTweets), 'the');
我得了零分。
我认为这是因为Twitter返回的结果格式不正确,无法与"substr_count"一起使用,但我不确定如何解决它,任何帮助将不胜感激。
如果有帮助,我正在使用亚伯拉罕的PHP库。
Twitter URL 返回 JSON 编码的响应,并且您正在使用它使用 substr_count(),因此请更改为:
$recentTweets = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=username');
$decoded = json_decode($recentTweets); //to array
//loop thru the $decoded array
//get text content and use substr_count() on it