使用PHP使用simplexml_load()显示所有提要

时间:2010-03-29 07:32:52

标签: php simplexml

我想循环获取所有Feed,但只显示一个

$url = "http://localhost/feeds/feeds.rss";

$xml = simplexml_load_file($url); 

    foreach($xml->item as $result){ 

        echo $result->description."<br>";

    }

RSS Feed是 -

<channel>
    <title>/</title>
    <link>/</link>
    <atom:link type="application/rss+xml" href="/" rel="self"/>
    <description>/</description>
    <language>/</language>
    <ttl>/</ttl>
  <item>
    <title>/</title>
    <description>/</description>
    <pubDate>/</pubDate>
    <guid>/</guid>
    <link>/</link>
  </item>
  <item>
    <title>/</title>
    <description>/</description>
    <pubDate>/</pubDate>
    <guid>/</guid>
    <link>/</link>
  </item>
</channel>

1 个答案:

答案 0 :(得分:-1)

解决方案是:

foreach($xml->channel->item as $result){ 

        echo $result->description."<br>";

    }