Skip to content

Making a database-free online RSS reader in PHP

I follow a number of blogs and forums, and I've been looking for a while for a good way to pull the RSS feeds from most of these into one place for easy reading. On my Linux machine, QuiteRSS works really well. I like the features and interface, but I work on multiple computers throughout the day, and at night I read on my phone, so I really wanted one central place to go for checking up on things. Not wanting to reinvent the wheel, I went looking at the existing options, focusing on self-hosted solutions, because I really didn't want to throw all of that data into another for-profit site that would use my feeds to throw ads at me. And while I can deal with using a private server to install a fully-fledged RSS reader, I didn't really want to bother with logging into another service, then worry about updating it, and seeing that it is still maintained, etc. An RSS reader that stores a username/password combo is just one more security issue to worry about, and means that I'd have to make sure it's not easy to hack and get into. I'm not super concerned about being able to add new feeds on the fly, because I'm usually pretty close to web development tools, or I can wait until I get around to them--it's not the end of the world if I can't add something immediately.

So instead I decided to build my own. The scripts I've put together and modified work without a database because you must edit the file directly in order to add them, so the collection of feed is as secure as your site hosting is, plus there are no SQL calls to worry about. It's viewable anywhere you can run PHP, so there's no bother with logging into anything, and of course that means you can share it all you want just by sending people the link. Since it's all processed server-side, it basically acts like a static site for all intents and purposes, which was exactly what I wanted. There are some small downsides--right now it doesn't support Atom feeds, and there aren't any sorting options, but I'll probably come back to it and add those in the future.

I figured I might not be the only one wanting to do this, so I figured I'd share it here. Under the cut I've put a download link and a short explanation on how it works, so that you can add it to your own site if you like. Feel free to leave any questions you have in the comments.

I started out with the script I found on Stackoverflow here:

This one works really well, but it's only meant for one feed, and the way it displays them is pretty basic. So I made a few additions to make it work for me.

$sites = array(
"MelonLand Recent Posts" => ";type=rss;limit=15",
"Yesterweb Recent Posts" => "",
...etc, etc
$feedlist = array();

First I separated the $feedList array into two different ones: a plaintext array that takes the rss feed link and a corresponding key for the feed's title ($sites), and the $feedList array itself that creates an array of rss objects. The custom object created by the original script didn't contain site name info, so this way I can keep them together and iterate through them when they're being displayed.

# this creates the array of objects
foreach($sites as $key => $value){
# print "Key: " . $key . "
Value: " . $value . "
$feedlist[$key] = new rss($value);

# sort the array alphabetically

This takes in the data you've thrown into the $sites array and adds it to the array of rss objects, and then sorts it alphabetically so that it looks nice.

Then I just had to write a couple of loops to display the page nav links and the feeds themselves:

foreach($feedlist as $key => $value){
# print the anchor links for page navigation here
echo "<li><a href='#" . $key . "''>" . $key . "</a></li>";

foreach($feedlist as $key => $value){
# print_r($feedlist[$key]);
echo $feedlist[$key]->display($postsToDisplay,$key);
print "<a href='#top' class='topLink'>Back to top</a>";

Everything else is handled by the objects themselves, so I didn't really need to change them much except to add some classes for styling.

But you don't really need to worry about most of that if you just want to use the script, all you have to do is edit the $sites array to add the sites you'd like to display. Then the script will take care of the rest of it from there.

If you'd like to see what it looks like, I've got a fully-styled page here:
Here's the same page without styling (warning: ugly) so that you can see how it degrades

Here's a link to the zipped files, which you can edit and use on your own site if you like: (2.8 kb)


No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Form options