使用 SimpleXML 获取 Twitter 提要并显示信息

发布于 2024-10-10 08:22:42 字数 763 浏览 0 评论 0原文

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

以下是提要网址(用于测试目的): Twitter feed< /a>

这是我的代码:

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。

有人可以帮我吗?

Based on the thread With PHP preg_match_all, get value of href, I'm trying to get some information from a twitter feed.

Here is the feed url (for testing purpose): Twitter feed

Here is my code:

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));

I never used SimpleXML before or worked with XML.

Can someone help me please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自演自醉 2024-10-17 08:22:42

好吧,Fouf 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++;
    }

Okay Founf it!, here is the solution for who is interested...
Thanks to m1k3y02 for the docs!

     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++;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文