ad

Parse and Display RSS Feeds with PHP

rss_icons

Display RSS feeds with PHP

In this article i will expalin to display blog’s RSS feeds with PHP. ┬áIts very useful when you want to display your recent articles on your websites with the help of blog feeds.

RSS feeds with PHP

Demo

PHP file where you want to display Feeds:
index.php: This is the code of the PHP file which will display the RSS feeds of the blogs.

<?php
include('rssclass.php');
$feedlist = new rss('http://http://feeds.feedburner.com/blogspot/VvkgzT');
echo $feedlist->display(10,"WebTips");
?>

PHP function simplexml_load_file() to load and read XML file. rssclass.php

<?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
$date=(string) $item->pubDate;
$rss_split[] = '<div><a href="'.$link.'" target="_blank" title="" >'.$title.'</a><br /><b>Posted On:</b>'.$date.'<br /> '.$description.'<hr></div>';
$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;
}
}
?>

Stylesheet code: This is the code of RSS ruls which will style the display of feeds. This is just a prototype. You can change this to match your blog’s design

.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;
}

Combine all these files in your website. Comments below in case of any problem with code.

Tags: | |
Nord VPN Sale

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.


Similar Articles

0 Comments

Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

2020 UseThisTip | Developed By Deepanker