【问题标题】:Get Twitter feed and display information using SimpleXML使用 SimpleXML 获取 Twitter 提要和显示信息
【发布时间】:2011-06-03 03:34:16
【问题描述】:

基于线程 With PHP preg_match_all, get value of href,我正在尝试从 twitter 提要中获取一些信息。

这是提要网址(用于测试目的):Twitter feed

这是我的代码:

function parse_feed($process) {
        $xml  = @simplexml_load_string($process);
        $findTweet = $xml['entry'];
    return $findTweet;
}

$username = 'tweet';
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=2";

$feed = file_get_contents($feed);
    //echo $feed;
print_r(parse_feed($feed));

我以前从未使用过 SimpleXML,也从未使用过 XML。

有人可以帮帮我吗?

【问题讨论】:

  • 仅供参考,您也可以将 .atom 替换为 .json 并使用 json_decode() 可能会更容易。
  • 哇!谢谢我明天试试! :P

标签: php xml twitter simplexml


【解决方案1】:

这个网站可能是一个好的开始http://www.php.net/manual/en/simplexml.examples-basic.php

【讨论】:

    【解决方案2】:

    Okay Founf it!,这是适合感兴趣的人的解决方案... 感谢 m1k3y02 提供的文档!

         function parse_feed($process) {
            $xml = new SimpleXMLElement($process);
            $n=0;
            foreach($xml->entry as $entry) {
                $tweets[$n] = array($entry->published,$entry->content);
                $n++;
            }
            return $tweets;
        }
    
        $twitter_username = 'tweet';
        $twitter_entries = 5;
        $feed = "http://search.twitter.com/search.atom?q=from:" . $twitter_username . "&rpp=".$twitter_entries;
    
        $feed = file_get_contents($feed);
        $tweets = parse_feed($feed);
        $n=0;
        $n_t = count($tweets);
        while($n < $n_t) {
            echo "<div class=\"tweet\"><img src=\"img/tweet.png\" valign=\"absmiddle\" /> ";
            echo $tweets[$n][1][0];
            echo "</div>";
            echo "<div class=\"date\">".$tweets[$n][0][0]."</div>";
            $n++;
        }
    

    【讨论】:

      猜你喜欢
      • 2013-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多