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

发布于 2024-08-26 18:19:18 字数 968 浏览 7 评论 0原文

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

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

$xml = simplexml_load_file($url); 

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

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

    }

RSS 提要 -

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

I want to loop to get all feeds, but displaying only one

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

$xml = simplexml_load_file($url); 

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

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

    }

RSS Feed is -

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

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

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

发布评论

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

评论(1

怀念你的温柔 2024-09-02 18:19:18

解决办法是:

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

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

    }

The solution is:

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

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

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