RSS feeds are everywhere, and everyone knows that it can be display RSS feeds on your website using third party widgets. Sometimes it’s a good idea to display one to keep people in the loop of important posts from your site. I am using PHP function simplexml_load_file() to load and read XML file.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Display feeds Using php API</title> <style type="text/css"> body{ font-family:"Trebuchet MS"; font-size:12px; } a{ color:#333333; text-decoration:none; } a:hover{ color:#0066CC; text-decoration:underline; font-weight:bold} hr{ color: #dedede; background-color: #dedede; height: 1px; } .vas{ float:left; width:270px; padding:10px; } .title-head { font-size:18px; font-weight:bold; text-align:left; background-color:#006699; color:#FFFFFF; padding:5px; } .feeds-links { text-align:left; padding:5px; border:1px solid #dedede; } .footer { font-size:11px; font-weight:bold; font-family:Verdana, Arial, Helvetica, sans-serif; } </style> </head> <body style="height:80px; background:url(http://freewebmentor.com/wp-content/uploads/2014/01/logo.png) top no-repeat"> <div style=" height:15px; padding-top:60px; text-align:center;padding-bottom:10px; color:#000; font-size:16px; "></div> <div style="height:20px"> <span style="float:right; font-size:16px"><img src="http://freewebmentor.com/wp-content/uploads/2014/01/logo.png" /><a href="http://feeds2.feedburner.com/freewebmentor">Subscribe My Feeds</a></span></div> <div> <?php include('rssclass.php'); $feedlist = new rss('http://feeds2.feedburner.com/freewebmentor'); echo $feedlist->display(10,"Freewebmentor"); $feedlist = new rss('http://wordpress.org/news/feed/'); echo $feedlist->display(9,"Wordpress.org"); ?> </div> </body> </html> |
Below is the class which will generate the rss feeds for any websites.
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <?php class rss { var $feed; function rss($feed) { $this->feed = $feed; } function parse() { $rss = simplexml_load_file($this->feed); $rss_split = array(); foreach ($rss->channel->item as $item) { $title = (string) $item->title; // Title $link = (string) $item->link; // Url Link $description = (string) $item->description; //Description $rss_split[] = ' <div> <a href="'.$link.'" target="_blank" title="" > '.$title.' </a> <hr> </div> '; } return $rss_split; } function display($numrows,$head) { $rss_split = $this->parse(); $i = 0; $rss_data = ' <div class="vas"> <div class="title-head"> '.$head.' </div> <div class="feeds-links">'; while ( $i < $numrows ) { $rss_data .= $rss_split[$i]; $i++; } $trim = str_replace('', '',$this->feed); $user = str_replace('&lang=en-us&format=rss_200','',$trim); $rss_data.='</div></div>'; return $rss_data; } } ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Feeds, get rss feeds, how to get rss feed of website, PHP, php script for rss feed, rss feeds php script, website rss feed