使用简单的 xml 读取 twitter 的 rss 搜索提要 [英] reading twitter's rss search feed with simple xml
本文介绍了使用简单的 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 <a href="http://twitter.com/TwittBoy">@TwittBoy</a>: <b>TwitFile</b> - Comparte tus archivos en Twitter (hasta 200Mb) <a href="http://bit.ly/xYNsM">http://bit.ly/xYNsM</a></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ó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
推荐答案
- 在代码中,为 $screenname 分配了一个值,但您正在回显 $author.
- 要在
google:image_link
等命名空间中获取元素,您必须执行以下操作:
- In the code, $screenname is assigned a value but you are echoing $author.
- 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屋!
查看全文