使用简单的 xml 读取 twitter 的 rss 搜索提要 [英] reading twitter's rss search feed with simple xml

查看:26
本文介绍了使用简单的 xml 读取 twitter 的 rss 搜索提要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 rss 提要中选择一些节点进行 twitter 搜索时遇到一些问题

Having some trouble selecting some nodes in the rss feed for twitter's search

RSS 网址在这里

http://search.twitter.com/search.rss?q=twitfile

每个项目看起来像这样

<item>
  <title>RT @TwittBoy: TwitFile - Comparte tus archivos en Twitter (hasta 200Mb) http://bit.ly/xYNsM</title>
  <link>http://twitter.com/MarielaCelita/statuses/5990165590</link>
  <description>RT &lt;a href=&quot;http://twitter.com/TwittBoy&quot;&gt;@TwittBoy&lt;/a&gt;: &lt;b&gt;TwitFile&lt;/b&gt; - Comparte tus archivos en Twitter (hasta 200Mb) &lt;a href=&quot;http://bit.ly/xYNsM&quot;&gt;http://bit.ly/xYNsM&lt;/a&gt;</description>
  <pubDate>Mon, 23 Nov 2009 22:45:39 +0000</pubDate>
  <guid>http://twitter.com/MarielaCelita/statuses/5990165590</guid>
  <author>MarielaCelita@twitter.com (M.Celita Lijer&#243;n)</author>
  <media:content type="image/jpg" width="48" height="48" url="http://a3.twimg.com/profile_images/537676869/orkut_normal.jpg"/>
  <google:image_link>http://a3.twimg.com/profile_images/537676869/orkut_normal.jpg</google:image_link>
</item>

我的php在下面

  foreach ($twitter_xml->channel->item as $key) {
$screenname = $key->{"author"};
$date = $key->{"pubDate"};
$profimg = $key->{"google:image_link"};
$link = $key->{"link"};
$title = $key->{"title"};
echo"
                        <li>
                        <a href=$link><img width=48 height=48 src=\"$profimg\"></a>
                        <h5><a href=$link>$author</a></h5>
                        <p class=info><a href=$link>$title</a></p>
                        </li>
";

问题是什么都没有得到回应,我的意思是从 rss 提要,如果有 20 个结果,它会循环 20 次,只是没有数据

Problem is nothing is being echoed, i mean from the rss feed, if there are 20 results, its looping 20 times, just no data

推荐答案

  1. 在代码中,为 $screenname 分配了一个值,但您正在回显 $author.
  2. 要在 google:image_link 等命名空间中获取元素,您必须执行以下操作:
  1. In the code, $screenname is assigned a value but you are echoing $author.
  2. To get elements within namespaces like google:image_link ,you will have to do this:

$g = $key->children("http://base.google.com/ns/1.0");$profimg = $g->{"image_link"};

如果您想知道我从哪里获得 "http://base.google.com/ns/1.0",请在 rss 提要的第二行中提到命名空间.>

If you are wondering where did I get "http://base.google.com/ns/1.0" from, the namespace is mentioned in the second line of the rss feed.

$url="http://search.twitter.com/search.rss?q=twitfile";
$twitter_xml = simplexml_load_file($url); 

foreach ($twitter_xml->channel->item as $key) {
    $author = $key->{"author"};
    $date = $key->{"pubDate"};
    $link = $key->{"link"};
    $title = $key->{"title"};
    $g = $key->children("http://base.google.com/ns/1.0"); 
    $profimg = $g->{"image_link"};
    echo"
                            <li>
                            <a href=$link><img width=48 height=48 src=\"$profimg\"></a>
                            <h5><a href=$link>$author</a></h5>
                            <p class=info><a href=$link>$title</a></p>
                            </li>
    ";
    $xml = $twitter_xml;
}

此代码有效.

这篇关于使用简单的 xml 读取 twitter 的 rss 搜索提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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