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 too often I’m #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 waste of time that my mashup codebase turned into, I realized I didn’t have anything new and 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 Muschamp.ca 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.

I haven’t had a lot of time for PHP or miniature painting or this blog the last few years but now that I’ve passed all three CFA® exams I need a new job and somehow I got it into my head to update and improve my blog, hopefully it will finally become an asset rather than an albatross. If you have any advice on finding a job you can leave it below. I’m not a very enthusiastic PHP coder, but I do have experience and plenty of coding samples.

Related Posts

4 Comments

Leave a Reply

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.

Posts on Muskblog © Andrew "Muskie" McKay.
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.