php - 使用 SimpleXML 通过 Laravel PHP 显示 RSS 提要

标签 php rss simplexml

我想显示 RSS 提要,并使其尽可能简单。

我正在使用 Laravel 4。 这是我的 Controller :

public function getHome()
{
    $content = file_get_contents('http://rss.leparisien.fr/leparisien/rss/paris-75.xml');
    $flux = new SimpleXmlElement($content);

    return View::make('frontend/homepage', compact('flux'));
}

这是我的观点:

@foreach ($flux as $flu)
    <article class="entry-item">
        <img src="{{utf8_decode((string)$flu->item->enclosure['url'])}}" alt="">
        <div class="entry-content">
            <a href="{{ $flu->item->link }}">{{ $flu->item->title }}</a>
            {{ $flu->item->description }}
        </div>
    </article>
@endforeach

这工作正常,但只显示一篇文章(项目)。 我试图找到一种方法来显示多个项目 SimpleXMLElement::attributes

我找不到任何关于它的明确教程。

最佳答案

试试这个

@foreach ($flux[0]->item->link as $item)
    <article class="entry-item">
        <img src="{{utf8_decode((string)$item->enclosure['url'])}}" alt="">
        <div class="entry-content">
            <a href="{{ $item->link }}">{{ $item->title }}</a>
            {{ $item->description }}
        </div>
    </article>
@endforeach

因为您有多个项目

关于php - 使用 SimpleXML 通过 Laravel PHP 显示 RSS 提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19621124/

相关文章:

php - 将多个复选框值写入数据库

php - 使用 PHP 拉入 RSS 提要时提取图像数据

php - simplexml,返回具有相同标签的多个项目

php - 函数 simplexml_load_string() 上的 XML_PARSE_HUGE

php - 从 XML 元素中删除开始和结束空格

php - EXCEL:如何在excel中添加背景标题颜色;使用 PHP 导出?

php - 使用 jQuery 检查单选按钮的值并更改 CSS 类

php - 更改 Yii 中的页面标签?

c# - 如何在网页中显示我的 Wordpress 站点的最新博客条目?

Python 提要解析器 : How can I check for new RSS data?