How To Parse RSS Feeds with MagpieRSS

Using MagpieRSS is one of the simplest ways to parse RSS feeds. One use of this is when you want to display updated contents from a site to your website. In this post, we are going to get the Top Stories news of “The Worldwide Leader in News”, the CNN. We will just use one of their RSS feed links: CNN provides all of their RSS feeds links, you can find them in this link We just have to agree to their terms of use listed on that page.

How To Parse RSS Feeds with MagpieRSS
Want some feeds?

Step 1: Download MagpieRSS on sourceforge (I got magpierss-0.72) and place it in your web directory. I got the following files:

Step 2: Coding.


        <title>Parsing RSS feeds with MagPie RSS</title>


//Specify the URL of RSS feeds
$rss = fetch_rss("");

foreach ( $rss->items as $item ) { //loop through the $rss array which contains the feeds
    echo "<div style='margin: 5px 0 5px 0;'>";
    echo "<div style='font-weight: bold;'>{$item['title']}</div>";
    echo "<div style=''>{$item['description']}</div>";
    echo "</div>";

If we will take a look at, we have:

On our index.php code, title and description inside $item variable are from the XML tags of RSS feed. If you will view-source, you will see:

This is an item in our RSS feed. The values between title and description tags are echoed in our program. You can also echo the link, pubDate, etc. since those tags are there too.
Step 3: Run the program. The ouput of our code would be something like:

You may want to:

That’s it! Now you can embed some contents from an RSS feeds to your website!

By Mike Dalisay

I'm Mike Dalisay, a pro web developer since 2010. I love web development. Improving our tutorials and source codes makes me happy. Do you want to suggest an edit to our tutorial? Got something to ask about our source codes? You may use our comments section below or email our team at [email protected]

1 comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top