得到一个特定的#标签的数量从Twitter PHP [英] getting the count of a specific hashtag from twitter PHP

查看:188
本文介绍了得到一个特定的#标签的数量从Twitter PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是能够得到一个特定的主题标签的所有Twitter的职位在PHP。现在什么是我想要得到的计数的总数为特定井号标签。
我使用卷曲,SimpleXMLElement对象以及Twitter的API调用搜索。
如何获得数量总数为具体包括hashtag任何想法?

 < PHP
$ PAGETITLE =拉Twitter的主题标签;
功能getTweets($ HASH_TAG){    $ URL ='http://search.twitter.com/search.atom?q='.urlen$c$c($hash_tag).'&result_type=recent';
    回声< P>连接到<强而GT; $网址< / STRONG> ...< / P>中;
    $ CH = curl_init($网址);
    curl_setopt($ CH,CURLOPT_RETURNTRANSFER,TRUE);
    $ XML = curl_exec($ CH);
    curl_close($ CH);//如果你想看到来自Twitter的响应,取消这下一部分出来:
//回声< P>响应:其中; / P>中;
//回声< pre>中的htmlspecialchars($ XML)。< / pre>中;    $影响= 0;
    $ twelement =新的SimpleXMLElement($ XML);
    的foreach($ twelement->条目$进入){
    $文字=修剪($入门>标题);
    $作者=修剪($入门>作者 - >名);
    $ =时间的strtotime($入门>公布);
    的$ id = $入门和SEQ ID;    //回声计数($入门>文字);
    :其中;强>中。从资料Tweet< P&GT$作者回声。$文字< / STRONG>< EM>发布.date('N / J / YG:我一个'。, $时间)。< / EM>< / p>中;
}返回true;
}getTweets('#匡威');
?>


解决方案

使用计数()

  $ number_of_tweets =计数($ twelement->输入);

i am able to get all twitter posts of a specific hashtag in PHP. What now is that i want to get the total number of count for that particular hashtag. i am using curl , SimpleXMLElement as well as twitter API search calls. Any idea on how to get the total number of count for that specific hashtag?

<?php
$pagetitle = "Pull Twitter Hashtags";


function getTweets($hash_tag) {

    $url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag).'&result_type=recent' ;
    echo "<p>Connecting to <strong>$url</strong> ...</p>";
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $xml = curl_exec ($ch);
    curl_close ($ch);

//If you want to see the response from Twitter, uncomment this next part out:
//echo "<p>Response:</p>";
//echo "<pre>".htmlspecialchars($xml)."</pre>";

    $affected = 0;
    $twelement = new SimpleXMLElement($xml);
    foreach ($twelement->entry as $entry) {
    $text = trim($entry->title);
    $author = trim($entry->author->name);
    $time = strtotime($entry->published);
    $id = $entry->id;

    //echo count($entry->text);
    echo "<p>Tweet from ".$author.": <strong>".$text."</strong>  <em>Posted ".date('n/j/y g:i a',$time)."</em></p>";
}



return true ;
}

getTweets('#converse');


?>

解决方案

Use count()

$number_of_tweets = count($twelement->entry);

这篇关于得到一个特定的#标签的数量从Twitter PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆