So awhile ago I had the idea of grabbing all the items from a vast swathe of rss feeds that I would regularly add to my google homepage if I actually had enough space for them all, and selecting a random set of items from all of those feeds to display. This evening I had a bit of time and decided to actually do it, since I reasoned it would be a fairly simple task. I had a quick google and found this, but that is a lot of stuff for what really only needs to be a small php script at best. After all, you’re only grabbing a bunch of current feeds, combining all their items, shuffling that item array and selecting the first n elements! So anyway, it was very simple after installing the pear XML_RSS package. I don’t do that much php and didn’t have much time, so forgive the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <?php echo "<?xml version='1.0'?>"; ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://my.netscape.com/rdf/simple/0.9/"> <channel> <title>Tavis' Random RSS Items</title> <link>http://smedleyisageek.net</link> <description>Ten random feed items from my favorite sources.</description> </channel> <?php require_once("XML/RSS.php"); $items = array(); $feeds = array( "http://rss.slashdot.org/Slashdot/slashdot", "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml", "http://feeds.digg.com/digg/container/technology/popular.rss"); foreach($feeds as $feed){ $rss =& new XML_RSS($feed); //assign by reference, not required in php5 + $rss->parse(); foreach ($rss->getItems() as $item) { $items[] = $item; } } shuffle($items); for($i = 0; $i < 9; $i++){ ?> <item> <?php echo "<title>".$items[$i]['title']."</title>\n". "<link>".$items[$i]['link']."</link>\n"; ?> </item> <?php } ?> |
It is unlikely to be useful to anyone, but as a very brief toy project it certainly suffices for my needs.
