Adding RSS or XML to php site
A lot of people locally have asked me how to add an xml or rss feed to their site. A lot of people may wonder what the benefits of adding a feed to your site and basically it keeps fresh content updating to your site. If the search engines come by and snap what you have got from your own personal content, then more content from a feed, it helps you get more traffic for different keywords.
It is rather simple, so simple that anybody can do it, techie or non-techie. I am going to show you how to do it briefly and then send you to a demo page to see it in action. First, you will need an rss aggregator script. The best free script to download is magpie. You can download it here.
For this post, I downloaded Magpie RSS 0.72 and extracted it to a folder on my local machine. If you don’t have a good zip program, you can download 7zip for free here. Once you extract the Magpie archive, it should automatically unzip to folder magpierss-0.72. You will want to rename the folder magpierss.
Next you will need to FTP this folder into your webhost. If you don’t have good FTP software, you can download Filezilla for free here. It is Open Source and very fast.
Now once this is done, on the php page that you want the feed to appear, somewhere in the code you will need to add the following line:
<?php
require_once('magpierss/rss_fetch.inc');
?>
Once you add that bit of code to the page, wherever you want the rss feed to appear, add the following code:
<?php
$url = "your_url_here";
$rss = fetch_rss ( $url );
echo "Channel Title: " . $rss->channel['title'] . "<p>";
echo "<ul>";
foreach ($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
$description = $item['description'];
echo"<li><a href=$href>$title</a></li><p>$description</p>";
}
echo"</ul>";
?>
If you use wordpress like I am using for this and my other blog, you can easily manipulate an rss feed into any page that you want to in your blog by adding the EXEC-PHP plugin for wordpress. It can be downloaded here: http://bluesome.net/post/2005/08/18/50/. Once you install the EXEC-PHP plugin, activate it and then paste the code above into any page of your blog by changing the following line:
$url = “your_url_here”;
Change the your_url_here to the url of the feed that you want to add to your site. Whenever you publish this, it goes live and is available for all of your site’s visitors.

Leave a Reply