我正在使用基本搜索 twitter api,我想获取响应中提到的特定单词的总数。这就是我的 api 调用的样子 -
$url = "https://api.twitter.com/1.1/search/tweets.json";
$requestMethod = "GET";
// Keyword to search
$getfield = '?q=elrond&count=20';
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(),$assoc = TRUE);
if(array_key_exists("errors", $string)) {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();}
echo "<pre>";
print_r($string);
echo "</pre>";
foreach($string as $array){
$i++;
}
echo $i;
当我 echo $i 时,我得到的计数为 2,但如果我查看实际响应,他们提到该关键字的次数超过 100 次。我将使用什么方法来计算关键字在响应中出现的次数?
这是我得到的响应示例 -
[1] => Array
(
[created_at] => Tue Aug 11 16:04:39 +0000 2020
[id] => 1293216771244261381
[id_str] => 1293216771244261381
[text] => @Meter_IO @ElrondNetwork You know just the right partnership, with elrond network, you are certainly in for something big. 🥳
[truncated] =>
[entities]
我将搜索 [text] 字段来获取计数
慕容708150