我想显示 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/