AFFORDABLE


How to add RSS feeds into your website using PHP



Hello Friends,
 
As a webmaster you would interested in having search engine friendly RSS feeds on your web pages because this can help with;

RSS in Javascript format is available from most RSS Publishers but what they do not tell you is that Javascript is not search engine friendly. What that means is search engines do not read Javascript. Any thing placed on your web pages in javascript format won't be read by the indexing search engines. That is why they offer our feeds in PHP. PHP is a search engine friendly scripting language. Adding RSS feeds to your web pages with PHP will provide fresh content for the search engines to choose up and rank you for.

PHP is server side scripting. That means it is parsed on the server before your page lots in the browser. To the visitor and to the search engines PHP scripts are not noticeable. When PHP is combined with RSS feeds it is a powerful idea. 

With PHP and RSS you can add other people's content to your web pages and the search engines will see it and think it is part of your net site! That free RSS content when placed on your web page with PHP will fundamentally become a part of your web-site and bring you more traffic. That is why they recommend that you add the feeds to your net site with PHP in lieu of Javascript. Follow the instructions below to add the code to your web pages.  Getting spidered more often Rating higher in the search engines  Adding Relevancy to your web page.

I had a lot of trouble trying to add RSS Feeds on my website. Eventually I came across these codes and they were very helpful.
PHP Code:
----------------------
class RSSFeed {
// VARIABLES
// channel vars
var $channel_url;
var $channel_title;
var $channel_description;
var $channel_lang;
var $channel_copyright;
var $channel_date;
var $channel_creator;
var $channel_subject;
// image
var $image_url;
// items
var $items = array();
var $nritems;
// FUNCTIONS
// constructor
function RSSFeed() {
$this->nritems=0;
$this->channel_url='';
$this->channel_title='';
$this->channel_description='';
$this->channel_lang='';
$this->channel_copyright='';
$this->channel_date='';
$this->channel_creator='';
$this->channel_subject='';
$this->image_url='';
}
// set channel vars
function SetChannel($url, $title, $description, $lang, $copyright, $creator, $subject) {
$this->channel_url=$url;
$this->channel_title=$title;
$this->channel_description=$description;
$this->channel_lang=$lang;
$this->channel_copyright=$copyright;
$this->channel_date=date("Y-m-d").'T'.date("H:i:s").'+01:00';
$this->channel_creator=$creator;
$this->channel_subject=$subject;
}
// set image
function SetImage($url) {
$this->image_url=$url;
}
// set item
function SetItem($url, $title, $description) {
$this->items[$this->nritems]['url']=$url;
$this->items[$this->nritems]['title']=$title;
$this->items[$this->nritems]['description']=$description;
$this->nritems++;
}
// output feed
function Output() {
$output =  '{C}'."\n";
$output .= ''."\n";
$output .= ''."\n";
$output .= ''.$this->channel_title.''."\n";
$output .= ''.$this->channel_url.''."\n";
$output .= ''.$this->channel_description.''."\n";
$output .= ''.$this->channel_lang.''."\n";
$output .= ''.$this->channel_copyright.''."\n";
$output .= ''.$this->channel_date.''."\n";
$output .= ''.$this->channel_creator.''."\n";
$output .= ''.$this->channel_subject.''."\n";

$output .= ''."\n";
$output .= '';
for($k=0; $k<$this->nritems; $k++) {
$output .= ''."\n";
};
$output .= ''."\n";
$output .= ''."\n";
$output .= ''."\n";
$output .= ''."\n";
for($k=0; $k<$this->nritems; $k++) {
$output .= ''."\n";
$output .= ''.$this->items[$k]['title'].''."\n";
$output .= ''.$this->items[$k]['url'].''."\n";
$output .= ''.$this->items[$k]['description'].''."\n";
$output .= ''.$this->items[$k]['url'].''."\n";
$output .= ''."\n";
};
$output .= ''."\n";
return $output;
}
};
You would use it like this :
php Code:
$myfeed = new RSSFeed();
$myfeed->SetChannel('http://www.mysite.com/xml.rss',
'My feed name',
'My feed description',
'en-us',
'My copyright text',
'me',
'my subject');
$myfeed->SetImage('http://www.mysite.com/mylogo.jpg');
$myfeed->SetItem('http://www.mysite.com/article.php?id=bla',
'name',
'description');
....
echo $myfeed->output();
I also discovered that there was a cron script that runs every now and then that writes the output to a an xml file.  It ran through a feed validator and was validated.
 
blog.brandwebdirect.com
For more information :- Custom  Facebook Website Design   Front Page Designer search on twitter



About the Author:

Narottam Agarwala

 Narottam Agarwala

About Author