Muschamp Rd

Merging feeds with SimplePie and PHP

April 27th, 2012
RSS Logo

I never set out to build a miniature painting news aggregator. I had time to do it because I remain #unemployed. I was just trying to help a fellow blogger out with a problem they were having. You know me, always helping other people, when I should be helping myself…

Anyway I spent even more time hacking away in one of my least favourite programing languages and unlike the huge basically waste of time that my mashup codebase was, I realized I didn’t have anything very useful I could share with my meager blog readership and folks who actually like to program in PHP.

I spent a lot of time reading the SimplePie documentation and code samples, Googling for solutions, and haunting StackOverflow, hoping someone had a solution to the problem I was having fetching multiple feeds from Blogspot. I answered the odd query, but I only use PHP on because it is available, back when I was a professional software developer we programmed in Objective-C and Java. A good programmer should be able to code in anything and hey at least it isn’t VBA right?

Without further ado here is a little bit of PHP that will take a text file containing one feed per line and merge them all into a single RSS feed. Exactly one item is included from each feed and they are sorted in chronological order. Thanks to the folks who made SimplePie and/or provided previous tutorials/code samples. This is basically an amalgamation of two previously documented techniques. You can download the code as a .txt file but I’ll try to figure out how to safely post the code below:

Let me know if you have any questions and/or problems I’ll try to answer them, but not all feeds are created equal, if you input improperly formatted or misbehaving feeds it will likely break, so choose your source feeds well. Line 71, the feed and item title can contain some improperly coded characters, so I changed it using a snippet of code found here.

Posts on Muskblog © Andrew "Muskie" McKay comments not necessarily so...
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.