2

I want to display a RSS feed, keeping it as simple as possible.

I am using Laravel 4. Here is my 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'));
}

And here is my view :

@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

This is working fine, but only one article (item) is shown. I tried to find a way to get several items displayed with SimpleXMLElement::attributes

I can't find any clear tutorial about it.

pimarc
  • 3,621
  • 9
  • 42
  • 70
  • 1
    Since this is basically a question on reading RSS with PHP, see [this existing question](http://stackoverflow.com/questions/250679/best-way-to-parse-rss-atom-feeds-with-php). In particular, note the way the `foreach` loop looks in [this answer](http://stackoverflow.com/a/251102/157957). – IMSoP Oct 27 '13 at 21:50

2 Answers2

2

try this

@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

because you have mutliple items

ddjikic
  • 1,254
  • 12
  • 28
2
@foreach ($flux->channel->item as $flu)
    <article class="entry-item">
        <img src="{{utf8_decode((string)$flu->enclosure['url'])}}" alt="">
        <div class="entry-content">
            <a href="{{ $flu->item->link }}">{{ $flu->title }}</a>
            {{ $flu->description }}
        </div>
    </article>
@endforeach
user3065326
  • 39
  • 1
  • 6