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.

1
  • 1
    Since this is basically a question on reading RSS with PHP, see this existing question. In particular, note the way the foreach loop looks in this answer. Commented Oct 27, 2013 at 21:50

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.