Quick and Easy Site Content with RSS and PHP

One of the many benefits of Really Simple Syndication or RSS is the promise of a constant stream of fresh and updated content to your website. As we all know, having new content on a regular basis delivers a Search Engine Optimization benefit because spiders seem to love new content. Of course, if the RSS feed is chosen carefully, the fresh content can also be a great service to your website’s readers. Get detailed information about the benefits of using RSS in your blog, on this website: https://www.mega-best.biz

Unfortunately, this promise of fresh content is often unfulfilled because dealing with the technology required adding this content to your site can seem confusing. Although the steps are actually pretty simple, getting content from an RSS feed added to your site can be daunting.

Some easy ways of adding an RSS feed to your site would be to use one of several free JavaScripts that are available on the web. Simply paste a few lines of JavaScript into your page and you are done. If all you care about is providing fresh content to your sites readers, this may be a good enough solution. One advantage of this solution is that since you are only adding scripting, you will not be linking to other websites in a way that a web spider will be able to see.

The fact that a web spider cannot see the updated content is also a liability of the JavaScript solution. We would prefer that GoogleBot and MSN recognize that we have new content on our sites and reward us for our efforts. If we are going to accomplish this goal, then we are going to have to come up with a solution that can turn the raw RSS/XML from the external feed into actual markup in our pages.

Doing this will require some programming ability on our part. We need a programming language that is quick, easy to learn, and is preferably not too much different from the standard HTML that we are used to. PHP is just about perfect for the job. PHP will allow us to write a short, simple program to fetch an RSS feed from a website, store a copy of that RSS feed locally for our own use, parse the appropriate data out of that feed, and then format a site bit with the HTML of our own choosing. (If that sounds difficult, don’t worry, I’ll step you through the process below)

How we will do this is ultimately going to be as easy for you as learning a new HTML tag, pasting it into your web page, and uploading a couple of files to your server. I am going to brush over the basics, but give you an exact step by step method to get RSS files fully parsed into HTML and added to your pages. I’m going to assume that you’ve already got a page ready to add your RSS feed to, that this page is a PHP or PHTML page, and you’ve already got your perfect RSS feed picked out.

For this demo I will use the RSS feed from Site-Reference ( Example 1 ). We will take the data from that feed, and transform it into some HTML we can use, and then take that HTML and place it on our sites and webpages.

The first thing that you will do is open a HTML or PHP editor. Windows notepad or WordPad will do. Now copy the code from the code sample ( Example 2 ) into your editor and save the file as SimpleReader.php. You can also save it as SimpleReader.txt and rename it later. Take a minute or so to look at what’s in this file, some of it may seem confusing but chances are some of it looks familiar too. Looks a lot like HTML doesn’t it ? Before you upload it, you may want to take a second to replace the default RSS URLs, with the URLs to other RSS feeds of your choosing. The part you should change looks like this:

// Here are the feeds - you can add to them or change them
$RSSFEEDS = array(
0 => "https://www.site-reference.com/xml.php?c=all",
1 => "http://rss.cnn.com/rss/cnn_topstories.rss",
2 => "http://rss.slashdot.org/Slashdot/slashdot",

To change the RSS feed that displays on your site, just change the first URL to the feed of your choice.

Upload this file to a location on your web server, and point your web browser at the file. The PHP code in the file will execute on your web server and send an HTML page down to your browser that has the RSS converted into a webpage. If we’ve done everything correctly what we should see is ( this ). For the novice who is reading, allow me to point out that the PHP in the file is executing on the web server, not in your browser like a html page. The output from the PHP script that runs on the server, is the page that you see in your browser. And it is this page that we are going to insert into your perfect page that’s awaiting its new RSS feed!

At this point we’ve got the RSS feed being converted to HTML, now we can take a few minutes to do a little bit of customizing if we want to and figure out how to get this HTML into our web page. Fortunately that’s just as easy!

Before you jump in and begin customizing, let’s take a moment to understand that what we are customizing here is not an entire page. We are customizing just a tiny “piece” of a page that is going to find a home in your own page.

Take a look at the file you saved, and notice that near the top there is some code that looks like this:

// Makes a pretty HTML page bit from the title,
// description and link
function FormatRow($title, $description, $link) {
return <<<HTML

<p class=”feed_title”>$title</p>
<p class=”feed_description”>$description</p>
<a class=”feed_link” href=”$link” rel=”nofollow” target=”_blank”>Read more…</a>
<p> </p>
<hr size=1>


To customize the format of the Feed Entries all we need to do is edit the HTML you see between the comments. Feel free to change anything you like and get as creative as you want. You can add any HTML you need such as Header tags, divs, spans, and tables. You probably guessed if you didn’t already know – $title, $description, and $link are the title description and link from the RSS feed. How you customize the HTML will depend where you plan to place the feed and the bigger picture of your entire page.

Now let’s have a look at your site or webpage and find a place where you would like the RSS feed to appear. Keep in mind that although it looked like a webpage when we looked at it in our browser, when we place it in our webpage then the styles and formatting from our site will take over and the feed will morph into the style of our website for a seamless fit.

When you find a good place on your website where you would like to install the feed, installing the feed is as easy as adding a new HTML tag. Put code exactly like the following into your layout and magic happens.


Upload the page to your server and the RSS feed is incorporated into your layout. As the data in the feed changes, the data displayed in your page changes, and since we are using PHP and not JavaScript our page changes as well and spider-bots will see fresh updated content.
If you’d like to do more with RSS and PHP, then be sure to check out Examples 3 and 4 from the RSS Demo Page. Example 3 shows you an enhanced version of the SimpleReader that we can use to place multiple feeds on a single page, and Example 4 shows you how it was used to create the demo. Get detailed information about the content management applications and platforms, on this website: https://www.startupcradles.com

Note: Some people have been having problems with this script, specifically getting a permissions error.Check out the thread we started in the forums about this article for the reason for this error. If you have any other questions or problems, you can ask them here…

John Holifield is a professional contract programmer and hobbyist PHP enthusiast residing in Pell City, Alabama. He is involved with several websites including Scary-Software.com, and he is a regular participant in the Site-Reference forums under the screen name “Mutilated1”.

Learn more about various methods of getting more traffic on your website, on this platform: www.123top.info