PHP : Smallest RSS feed script

PHP Logohi, normally when I need to fetch an RSS feed in private project I used some old script based on the php function fopen. But with my current Host (Dreamhost) fopen is dissables for various security reason, they however adviced to use the cURL library, I wasn’t familiar with it but after some reading and testing I’ve build an super small feedreader, well see for yourself . (Oh and you need to have the XML parser module installed on your server).


if (isset($_GET["url"]) and $_GET["url"] != "" ) {   $url = $_GET["url"];
$t=0;
$buff="";
if(isset($_GET["name"]) && $_GET["name"] != "" ? $name = $_GET["name"] : $name = "Feed" );
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$xml = simplexml_load_string(curl_exec ($curl));

foreach ($xml->channel->item as $item){
if ($t < 5 ){
$buff.= "<li id=\"lastfm_li\"><a href=\"$item->link\">$item->title</a></li>\n";
$t++;
}
}
curl_close ($curl);
$content.="<div id=\"feed_div\"><p id=\"boxheader\">".$name."</p>\n";
$content.="<ul id=\"feed_ul\">\n";
$content.= $buff;
$content.="</ul>\n";
$content.="</div>\n";

echo $content;
}

Usage.

Save the file on the server call it like this

http://someserver.com/yourfile.php?url=http://urltofeed.com/feed
optional is the name for the feed.

have comments leave them here, and I’ll try to respond as soon as possible!!

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • Furl
  • Live
  • Ma.gnolia
  • NewsVine
  • StumbleUpon
  • Technorati
  • TwitThis
  • Chawlk
  • Propeller
  • Ycombinator
Tags: , , , ,

4 Responses to “PHP : Smallest RSS feed script”

  1. Eric Says:

    Nice, not bad at all! Although, should note, SimpleXML is PHP5 only. Also, in your post, it converted && to &&, so before anyone tries to run the script, you need to manually edit that.

  2. Eric Says:

    In the previous post, that should have been:

    “it converted && to it’s html entity”

  3. sebastiano Says:

    oh thanks for that notification Eric! I’ll change it right away, and yes you are right it is PHP5 only, but I think only cavemen are still running php4! :)

  4. tamra Says:

    The toughest thing about success is that you’ve got to keep on being a success. Talent is only a starting point in this business. You’ve got to keep on working that talent. Someday I’ll reach for it and it won’t be there.

Leave a Reply