is this possible? I've been looking around and googling but can't find any scripts to do this... do you guys know of any? Thanks
Hi MarcNYC, I was just reading this thread about using Yahoo Pipes with multiple feeds: http://www.webmasterworld.com/rss_atom/3809232.htm I'm sure you could do it in PHP...the trick is to grab all the feeds and put them in a data stucture that you can manipulate the way you want. A quick and dirty approach would be using regular expressions. Or you could use a DOM XML parser or some function designed to parse RSS.
<?php class Feed_Amalgamator { public $urls = array(); public $data = array(); public function addFeeds( array $feeds ) { $this->urls = array_merge( $this->urls, array_values($feeds) ); } public function grabRss() { foreach ( $this->urls as $feed ) { $data = @new SimpleXMLElement( $feed, 0, true ); if ( !$data ) throw new Exception( 'Could not load: ' . $feed ); foreach ( $data->channel->item as $item ) { $this->data[] = $item; } } } public function amalgamate() { shuffle( $this->data ); $temp = array(); foreach ( $this->data as $item ) { if ( !in_array($item->link, $this->links($temp)) ) { $temp[] = $item; } } $this->data = $temp; shuffle( $this->data ); } private function links( array $items ) { $links = array(); foreach ( $items as $item ) { $links[] = $item->link; } return $links; } } /********* Example *********/ $urls = array( 'http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/teams/m/man_city/rss.xml', 'http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/teams/l/liverpool/rss.xml' ); try { $feeds = new Feed_Amalgamator; $feeds->addFeeds( $urls ); $feeds->grabRss(); $feeds->amalgamate(); } catch ( exception $e ) { die( $e->getMessage() ); } foreach ( $feeds->data as $item ) : extract( (array) $item ); ?> <h2><a href="<?php echo $link; ?>"><?php echo $title; ?></a></h2> <p><?php echo $description; ?></p> <p><em><?php echo $pubDate; ?></em></p> <?php endforeach; ?> PHP:
Thanks SO MUCH for posting this code man! Yesterday late night I actually found (before I read your code) this thing called SimplePie which seems perfect... I haven't been able to do multiple feeds yet so I am messing with that... If i can't get it to do multiple I'll give up and give a try to your code, which seems like it would do the right thing. Thanks again for taking the time
I just wrote it for you now, it works for BBC Feeds (and removes link repeats.) but I make no guarantees it'll work for every feed out there, especially malformed ones. Dan.
Wow you wrote this specifically for me? I am touched and feel bad now... I am definitely going to give it a try now! Thanks so much, even more so than before. French-webbie, I had indeed mentioned that I had found SimplePie but have been having trouble with multiple feed... If you have any experience with multi-feed SimplePie I could use your help maybe...
Yes Danltn, French-webbie didn't read every part of the thread but I wouldn't gang up on somebody who pitched in for help, at least he/she took the time and I appreciate that. You guys have all been great! Come on now, peace not war! ;-)
Heh my routine is go to forums, open every unread in a new tab, and either criticise others rolleyes or add my own replies... Some posts, the OP is just so frustrating to work with, I give up and close it. Dan.
Will it be difficult to input the feeds from a txt file? I have some 200 rss feeds i need to agregate and i was trying to categorize them, so i have 10 txt files i need to input and i was thinking if i could do that without writing them in the code.
Apologies for bringing up an old thread. A feed I want to display features a <content:encoded> tag, is there a way to use the script provided by Danltn to also display this? Thanks
You might also want to take a look at zRSSFeed zazar.net/developers/zrssfeed/ All it takes is one line on your p a g e [can't imagine why the site doesn't like that word] per feed.
Hello Sorry to open this old topic but i need for a website a multiple reader rss , this one works but i need to catch the enclosure , someone can modify this code for the JPG image of enclosure ? Thanks