Home arrow PHP arrow Page 4 - Web Services: MagpieRSS

Aggregating Feeds - PHP

In this second part of a five-part series on Web Services, you will learn how to install and use MagpieRSS, a popular RSS parser. This article is excerpted from chapter 20 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

TABLE OF CONTENTS:
  1. Web Services: MagpieRSS
  2. How Magpie Parses a Feed
  3. Retrieving and Rendering an RSS Feed
  4. Aggregating Feeds
By: Apress Publishing
Rating: starstarstarstarstar / 1
July 29, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Of course, chances are you’re going to want to aggregate multiple feeds and devise some means for viewing them simultaneously. To do so, you can simply modify Listing 20-2, passing in an array of feeds. A bit of CSS may also be added to shrink the space required for output. Listing 20-3 shows the rendered version.

Listing 20-3. Aggregating Multiple Feeds with Magpie

<style><!--
p { font: 11px arial,sans-serif; margin-top: 2px;}
//-->
</style>

<?php
require("magpie/magpie.php"); 

// Compile array of feeds
$feeds = array(
"http://localhost/book/20/blog.xml", "http://news.com.com/2547-1_3-0-5.xml", "http://rss.slashdot.org/Slashdot/slashdot");

// Iterate through each feed
foreach ($feeds as $feed) {

   // Retrieve the feed
   $rss = fetch_rss($feed);

   // Format the feed for the browser
   $feedTitle = $rss->channel['title'];
   echo "
"<p><strong>$feedTitle</strong><br />";

   foreach ($rss->items as $item) {
      $link = $item['link'];
      $title = $item['title'];
      $description = isset($item['description']) ? $item['description'].
                    
"<br />" : "";
     
echo "<a href="$link">$title</a><br />$description";
   
}
  
echo "</p>";

}

?>

Figure 20-3 depicts the output based on these three feeds.


Figure 20-3.  Aggregating feeds

Although the use of a static array for containing feeds certainly works, it might be more practical to maintain them within a database table, or at the very least a text file. It really all depends upon the number of feeds you’ll be using and how often you intend on managing the feeds themselves.

Please check back next week for the continuation of this article.



 
 
>>> More PHP Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: