How to Build a PHP-based RSS Feed Parser

How to Build a PHP-based RSS Feed Parser

Recently, I was building a website for a telecommunications startup and because they didn’t have a lot of content for their website, I suggested they use the content from a Yahoo Finance RSS feed. In today’s article, I will demonstrate how to write a simple function in PHP that allows you to display content from an RSS feed.

Wikipedia defines a parser as a part of a compiler, or an interpreter, which checks for proper syntax and builds a data structure based on that syntax. In this tutorial, we will take a look at how the PHP parser creates an array in which each element will contain the data found in the RSS feed items. However, I will go into more details when we start writing the PHP code.

I won’t go much into the XHTML/CSS code in this tutorial. Instead, I’ll focus on the PHP side. We’ll be creating a simple site with just two pages; home and news. The idea is to write two PHP functions that will spit out different content; one is for the display of the titles from the feed, and the other is for the content that will appear in a list form like those of a blog archive.

RSS Feed Parser

[tut demo=”http://www.onextrapixel.com/examples/rss-feed-parser/” download=”http://www.onextrapixel.com/examples/rss-feed-parser/rss-feed-parser.zip”]

The Design

This is how the finished website will look.

Final

The design is simple and sleek, nothing too fancy. All it takes is fifteen minutes in Photoshop, using gradients and a bokeh effect for the header design. If you have any questions regarding the creating of this layout, feel free to ask in the comment box at the end of this article.

Before going into the HTML for the site, this is how you should organize the file structure for the finished website:

Folders

We have one folder containing all the images that appear in the site; two PHP files, one for each page and one containing the functions; and a CSS file. Our site in today’s tutorial is extremely simple as such just a folder to contain the images is sufficient to ensure good organization of your files. However, if you are building a more complex site, it is advisable to create another folder titled ‘includes’ or ‘scripts’ so that you can move the functions.php file there. Also, if you have multiple style sheets, adding a folder titled ‘CSS’ would help keep your files organized as well.

For PC users, you can try the same local web server I use, XAMPP or try WAMP. If you are a MAC user, try MAMP.

The HTML

We are creating a rather simple two column website layout, as such the design markup should be easy to understand. However, if you’re new to web design, I recommend reading this wonderful tutorial on NETTUTS where you will be able to find explanations for most of the HTML/CSS techniques used here.

Whenever you’re starting to code a website, I suggest that you finish the HTML side and only then move onto styling the page with CSS. That way you won’t have some newly added elements break the layout that you’ve spent hours fitting together.

We start our index.php file with the doctype declaration and the head tag. After opening the body tag, we add the top navigation as an unordered list and wrap it in a container DIV:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Fictive Company</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>

<body>
<div class="container">
	<ul id="nav">
		<li><a href="index.php">Home</a></li>
		<li><a href="news.php">News</a></li>
	</ul>
</div>

Later, we will style the container DIV so that it centers the content and keeps it 960 pixels wide to avoid horizontal scrolling on smaller resolutions.

Next, we add the logo and the header DIV that will have the bokeh effect background:

<div id="header">
	<div class="container">
		<a id="logo" href="index.php">Fictive Company</a>
	</div>
</div>

In the main body of the page, we have the central column and sidebar column wrapped in a container DIV:

<div class="container">
	<div id="main">
		<div class="central">
			<div class="box">
				<h1>Welcome to the Fictive Company Website</h1>
				<p>Lorem Ipsum...</p>
			</div>
		</div>

In the sidebar, we have two box DIVs, one for the news titles that is pulled from the RSS feed, and another for a list of links, like the blogroll used in WordPress. We finish with two closing DIV tags, one for the container, and the other for the main DIV.

<div id="sidebar">
			<div class="box">
				<h2>News Feed</h2>
				<!--This is where the news titles will go.-->
			</div>

			<div class="box">
				<h2>Blogroll</h2>
				<ul class="blogroll">
					<li><a href="http://www.onextrapixel.com/">Onextrapixel</a></li>
					<li><a href="http://10steps.sg/">10Steps.SG</a></li>
					<li><a href="http://www.csswebsites.nl/">CSS Websites</a></li>
				</ul>
			</div>
		</div>
	</div>
</div>

Finally, the footer is added and we close the body and HTML tags:

<div class="container">
	<div id="footer">
		<p id="copyright">Copyright © 2009. by <strong>Fictive Company</strong>. All Rights Reserved.</p>
	</div>
</div>

</body>
</html>

Here is what the page looks like without any styles applied:

Without Style

The CSS

I start the CSS files for all my projects with a slightly modified version of Eric Meyer’s CSS Reset. The CSS reset will save you from a lot of headaches, so do consider using one. Also, it is useful to use little titles as comments so that you can find your way around your CSS files more easily if you have to edit something later.

/* RESET */
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-weight: inherit;
	font-style: inherit;
	font-size: 100%;
	font-family: inherit;
	text-decoration: none;
}
:focus { outline: 0 }
strong { font-weight: bold }
em { font-style: italic }
ol, ul { list-style: none }
a img { border:none } /* Gets rid of IE's blue borders */

I have removed some of the rules that aren’t needed for this website (like tables and blockquotes). You can also remove some of the selectors form the first rule (again: tables, blockquotes, form elements etc.) but I usually leave them there in case there is something I need to add later.

The following section is titled typography because it mainly sets various text properties.

/* TYPOGRAPHY */
body {
	color: #333;
	background: #f2f2f2 url(images/bgBody.png) repeat-x;
	font: 14px/20px Candara, Arial, Helvetica, sans-serif;
	text-align: justify;
}

p { margin-bottom: 20px }
p.desc { margin-bottom: 10px }
p.date { color: #555; font-style: italic }

a { color: #3674b2 }
a:hover { border-bottom: 1px solid #3674b2 }

h1 {
	font: 24px/30px Corbel, Arial, Helvetica, sans-serif;
	font-weight: bold;
	letter-spacing: 1px;
	text-shadow: 0 1px 0 #fff;
	margin-bottom: 15px;
	border-bottom: 1px solid #614578;
	color: #614578;
}

h2 {
	font: 20px/26px Corbel, Arial, Helvetica, sans-serif;
	font-weight: bold;
	text-shadow: 0 1px 0 #fff;
	margin-bottom: 10px;
	border-bottom: 1px solid #614578;
	color: #614578;
}

h1 a, h2 a, h1 a:hover, h2 a:hover { border: none }

ul.blogroll li {
	font-size: 18px;
	line-height: 23px;
	text-align: left;
	margin-bottom: 5px;
	border-bottom: 1px dotted #999;
}

ul.blogroll li:hover { border-bottom: 1px solid #999 }
ul.blogroll li a:hover { border: none }

Next, we will set the rules for the main layout elements:

/* LAYOUT */
.container {
	width: 960px;
	margin: 0 auto;
}

/* HEADER */
#header {
	background: url(images/bgHeader.png) no-repeat top center;
	height: 150px;
	margin: 0 0 30px;
}

#header .container { padding-top: 35px }

#logo {
	background: url(images/logo.png) no-repeat;
	width: 453px;
	height: 80px;
	text-indent: -9999px;
	display: block;
}

#logo:hover { border: none }

/* Navigation */
#nav { text-align: right }
#nav li { display: inline; margin-left: 30px }
#nav li a {
	line-height: 40px;
	color: #7c2c47;
	font-size: 20px;
	text-shadow: 0 1px 0 #fff;
}
#nav li a:hover { border: none; text-shadow: 0 0 3px #7c2c47; }

And now for the main content:

/* MAIN */
#main {
	clear: both;
	float: left;
}

.central {
	width: 630px;
	margin-right: 30px;
	float: left;
}

#sidebar {
	width: 300px;
	float: left;
}

.box {
	background: #e6e6e6 url(images/bgBox.png) repeat-x;
	border: 2px solid #d9d9d9;
	padding: 8px 15px 18px;
	margin-bottom: 30px;
	border-radius: 12px;
	-moz-border-radius: 12px;
	-webkit-border-radius: 12px;
}

I’ve added three border radius properties to the box class. The first one, the border-radius, is the official CSS3 property which currently isn’t supported by any of the top five browsers. Although the new pre-alpha release of Opera 10.50 adds support for the border-radius property, it is not widely used. The other two properties, with –moz- and –webkit- prefixes, are for Gecko- and Webkit-based browsers, respectively.

With the above code, you’ll be able to see nice, smoothly rounded corners if you view this page with Safari, which is used for screenshots in this tutorial. Google Chrome and Mozilla Firefox are also popular browsers that will give you the same view shown here. Unfortunately, current versions of Opera and Internet Explorer (IE) do not support CSS rounded borders. However, you can add rounded borders with the use of JavaScript in Opera and IE but that is beyond the scope of this tutorial.

Finally, we style the footer:

/* FOOTER */
#footer {
	text-align: center;
	clear: both;
	margin-bottom: 18px;
	padding-top: 18px;
}

#copyright {
	font-size: 17px;
	color: #555;
}

This is how the page will turn out after the styles have been applied:

With Style

You’ll notice that the News Feed box is empty. That’s because we still haven’t written the PHP functions that will parse the RSS feed and display its content.

The PHP

Before we start writing our parser, we will discuss the different RSS specifications. Onextrapixel’s RSS feed, which we’ll use for this tutorial, is based on the RSS 2.0 specification. The syntax of this specification is rather simple XML:

<rss version="2.0">
<channel>
<title>Onextrapixel - Showcasing Web Treats Without Hitch</title>
<link>http://www.onextrapixel.com</link>
<description>A digital playground for web designers and developers by sharing freebies, great tutorials, useful resources and online tips.</description>
<item>
	<title>Item Title</title>
        <link>http://www.onextrapixel.com/</link>
        <description>Post or article description (post excerpt)</description>
	<pubDate>Thu, 17 Dec 2009 07:46:56 +0000</pubDate>
</item>
<item>
	<title>Item Title</title>
        <link>http://www.onextrapixel.com/</link>
        <description>Post or article description (post excerpt)</description>
	<pubDate>Thu, 17 Dec 2009 07:46:56 +0000</pubDate>
</item>
</channel>
</rss>

Each feed entry is wrapped in the item tag and contains several tags that are of interest to us. We will be using the title, link, description and pubDate tags.

Some sites use other RSS specifications, like 0.91 and 1.0. Both are compatible with the RSS parser that we are about to write. However, it is worth noting that the 1.0 specification misses the pubDate tag; other than that, the feed should be parsed with no problems.

Finally, we create the functions.php file and start writing the functions that will read the content of the XML file containing the RSS feed.

The simpler code, listing the titles, looks like this:

function parserSide($feedURL) {
	$rss = simplexml_load_file($feedURL);
	echo "<ul class='newsSide'>";
	$i = 0;
	foreach ($rss->channel->item as $feedItem) {
		$i++;
		echo "<li><a href='$feedItem->link' title='$feedItem->title'>" . $feedItem->title . "</a></li>";
		if($i >= 5) break;
	}
	echo "</ul>";
}

Here, I will explain the purpose of each line of code for beginners to understand. For the more experienced individual, please put up with me for the meantime.

function parserSide($feedURL) {
	$rss = simplexml_load_file($feedURL);

We have declared a function parserSide that passes the feedURL variable from the page into the function. Then we’ve assigned the contents from the XML file at that URL to the rss variable. The simplexml_load_file function reads the contents of an XML file and converts it to an object.

echo "<ul class='newsSide'>";
	$i = 0;

Next, we’ve echoed out the opening unordered list tag and gave it a newsSide class so that we can easily style it later. We have also set a counter variable, i, to a value of zero.

foreach ($rss->channel->item as $feedItem) {
		$i++;
		echo "<li><a href='$feedItem->link' title='$feedItem->title'>" . $feedItem->title . "</a></li>";
		if($i >= 5) break;
	}
	echo "</ul>";
}

We have come to the foreach loop that will spit out the list items, i.e. news titles wrapped in anchor tags. As I’ve already said, all RSS feed items are wrapped in a channel tag, so to get to the content of the actual item we set the value of the feedItem variable to equal $rss->channel->item.

The first thing that we do inside the loop is increase the value of the i counter by one. Next, we echo out the list item tags, inside which we’ll place the linked title of the post:

echo "<li><a href='$feedItem->link' title='$feedItem->title'>" . $feedItem->title . "</a></li>";

You’ll notice that not everything we echo out is between the double quotation marks. Instead we have used the dot symbol to concatenate parts of the code that will be echoed out. We do this is because PHP understands anything between double quotes as a string, while we need to echo out the contents of the variables as HTML. At the end of this tutorial, I have added a link to a post that explains the concatenation of strings in more detail.

Finally, we check if the counter is equal or greater than a specific number we choose. In case you want to list ten items, you would simply write: if($i >= 10) and the loop would end after listing ten items. We close the loop with the curly bracket, echo the end unordered list tag and close the curly brackets for the function.

Now, we have to add two little bits of PHP to the index.php file which has so far contained only HTML. We add the following block of code just after the body tag:

<?php require_once "functions.php"; ?>

This will include the functions file so that we can make use of the functions inside of it. The other bit is calling the parserSide function and telling it which RSS feed to parse. We add this line of code just after the H2 tags containing the News Feed title:

<?php parserSide("http://feeds.feedburner.com/onextrapixel"); ?>

Let’s take a look at our progress so far.

News Feed

If you click on the image to view it full size, you will see that the content is pushed down by about twenty pixels. This is a result of the first PHP code we added after the body tag. The browser sees it as content and shifts everything below it. To fix this, we will wrap the PHP snippet of code in a DIV that will be absolutely positioned so that it doesn’t interfere with our content. We’ll also make it zero sized, just to be on the safe side.

<div id='zero'><?php require_once "functions.php"; ?></div>

And the CSS for our zero DIV:

#zero {
	position: absolute;
	top: 0;
	left: 0;
	width: 0;
	height: 0;
}

And, voilà:

Absolute Positioned

I feel that the look of the list items need more work, so we’ll be adding some styles to the newsSide class:

ul.newsSide li {
	text-align: left;
	margin-bottom: 5px;
	border-bottom: 1px dotted #999;
}

And we use the border styles from the blogroll class:

ul.blogroll li:hover, ul.newsSide li:hover { border-bottom: 1px solid #999 }
ul.blogroll li a:hover, ul.newsSide li a:hover { border: none }

Now it looks much better:

2nd PHP Function

Now we need to create the second PHP function but, before that, open the index.php in your favourite text editor and save it as news.php. Inside of news.php we make a few small changes. In the central DIV we change the H1 title to Company News and we replace the paragraph tags with the following:

<?php parser("http://feeds.feedburner.com/onextrapixel"); ?>

Your central DIV should look like this:

<div class="central">
	<div class="box">
		<h1>Company News</h1>
		<?php parser("http://feeds.feedburner.com/onextrapixel"); ?>
	</div>
</div>

From the sidebar, we remove the box DIV containing our feed item titles, so the sidebar DIV looks like this:

<div id="sidebar">
	<div class="box">
		<h2>Blogroll</h2>
		<ul class="blogroll">
			<li><a href="http://www.onextrapixel.com/">Onextrapixel</a></li>
			<li><a href="http://10steps.sg/">10Steps.SG</a></li>
			<li><a href="http://www.csswebsites.nl/">CSS Websites</a></li>
		</ul>
	</div>
</div>

Now we’ll go back to the functions.php file to write the second function. The second function is a little more complex because we will be echoing out post titles, content excerpts, publication dates and a ‘Continue Reading’ line. However, the logic is the same, so it shouldn’t be too hard to understand.

function parser($feedURL) {
	$rss = simplexml_load_file($feedURL);
	echo "<ul class='news'>";
	$i = 0;
	foreach ($rss->channel->item as $feedItem) {
		$i++;
		echo "<li>
			<h2 class='news'><a href='$feedItem->link' title='$feedItem->title'>" . $feedItem->title . "</a></h2>
			<p class='desc'>" . $feedItem->description . "</p>
			<p class='date'>Posted on: " . $feedItem->pubDate . "<a class='cont' href='$feedItem->link' title='$feedItem->title'>Continue Reading</a></p>
		</li>";
		if($i >= 5) break;
	}
	echo "</ul>";
}

We start with an unordered list with a different class this time; please note that we add the class news because the styling will be different. Inside the foreach loop, we first echo out the list items tags and then a linked title wrapped in H2 tags.

Next we wrap the content excerpt inside a paragraph tag and give it a class of desc, because we will style it to have a smaller bottom margin, then another paragraph tag with a date class. Inside of which, we will show the date on which the item was posted and also a link to the full post. We’ll also add a ‘Continue Reading’ link inside the date paragraph and assign a cont class to it.

Here is a preview of the News page:

News Page

The look of the news items isn’t quite to my liking so I will make use of the classes I’ve assigned to various elements and create some more CSS rules:

h2.news {
	padding: 3px 8px;
	margin-bottom: 5px;
	background-color: #eee;
	border: none;
	border-radius: 8px;
	-moz-border-radius: 8px;
	-webkit-border-radius: 8px;
}
h2.news:hover { background-color: #fff }

p.desc { margin-bottom: 10px }
p.date { color: #555; font-style: italic }

a.cont { display: block; float: right; font-style: normal }

The H2 headings containing the news titles will no longer be underlined; instead, they will have a nice background with rounded corners. Next, the paragraph containing the content will have a smaller bottom margin so that everything comes together more nicely. We make the date appear in an italic font and a little lighter and make sure that the ‘Continue Reading’ link stays non-italic and we also float it to the right.

Continue Reading

Now it looks much better. The date format however, needs more work. Fortunately, that is rather easy to change. All we need to do is make a few modifications to the functions.php file. The foreach loop in out parser function will now look like this:

foreach ($rss->channel->item as $feedItem) {
	$i++;
	$myDate = ($feedItem->pubDate);
	$dateForm = explode(" ", $myDate);
	echo "<li>
		<h2 class='news'><a href='$feedItem->link' title='$feedItem->title'>" . $feedItem->title . "</a></h2>
		<p class='desc'>" . $feedItem->description . "</p>
		<p class='date'>Posted on: " . $dateForm[1] . ". " . $dateForm[2] . ". " . $dateForm[3] . "." . "<a class='cont' href='$entry->link' title='$entry->title'>Continue Reading</a></p>
		</li>";
		if($i >= 5) break;
	}

We take the date from the $feedItem->pubDate and assign it to the myDate variable. Next, we make use of PHP’s explode function. The explode function takes a string and splits its content into an array at specific delimiter strings. In our case, this means that the original date string will be split at any space character and the substrings will then be put into an array.

The function has two arguments; the first one, in double quotes, is the delimiter and the other argument is the source string. Now that we have split our original date string, we can display it in any way we chose:

<p class='date'>Posted on: " . $dateForm[1] . ". " . $dateForm[2] . ". " . $dateForm[3] . "." . "<a class='cont' href='$entry->link' title='$entry->title'>Continue Reading</a></p>

I prefer my display date to be in the European format – day, month, and year. So I’ve used the first three elements in the dateForm array in their original order. If you prefer a different date format, you can chose to rearrange them in any way you like.

Here it the final look of the News page:

Date Format

In case you wanted to include the time, you would explode the fifth element in the dateForm array ($dateForm[4], because 0 is the first item), set the colon as the delimiter and you’d get an array with three elements: hours, minutes, seconds.

[tut demo=”http://www.onextrapixel.com/examples/rss-feed-parser/” download=”http://www.onextrapixel.com/examples/rss-feed-parser/rss-feed-parser.zip”]

In Closing

That would sum up this tutorial. I hope that it was easy to understand and that you enjoyed it. Below are the links that you might find useful and if you have any questions or suggestions on improving this tutorial or if you have a tutorial request, please don’t hesitate to mention it in the comment below.

Useful Links

Marko is a freelance web designer & developer based in Serbia. He is always trying to improve his skills and create a better user experience for his clients. These days he is getting into writing and getting closer & closer to getting his degree in mechanical engineering.

Comments

    • Peter,
    • December 24, 2009
    / Reply

    Nice tutorial!

    Not only learned how to make a PHP parser, but also some new HTML & CSS stuff.

    1. / Reply

      Thanks! Glad you enjoyed it and learned something new. :)
      Which of the HTML/CSS stuff was new to you? Is there some other HTML/CSS technique that you would like to see explained in a tutorial?

  1. / Reply

    Marko, a very descriptive tutorial that will help a lot of people. My only concern is how you parse the RSS feeds. It has no caching at all. Not only is that bad for your site’s load time, but your potentially hammering the source feed as well.

    I use SimplePie.org to handle my parsing. It has caching plus a lot of other neat features.

    1. / Reply

      Hi Brant, thanks for replying.
      I am aware of the shortcomings of this method and I know that using SimplePie is much easier (and better). But, had I said so, no one would bother reading the tutorial. ;) The point of this tutorial was to get people familiar with PHP and this method of parsing RSS. Maybe I can now write a second part of this tut, one that explains using SimplePie and all of its benefits…

  2. / Reply

    This is exactly what I need! Great tutorial Marko.

    Thanks

    1. / Reply

      Thank, Nikola! :)
      Glad to be able to share the knowledge. ;)

  3. / Reply

    Thank you so much for sharing. I’ve never known there is simplexml_load_file function. I’ve been using MagpieRSS for RSS reader on my websites.
    Great tutorial.

    • Joel,
    • December 25, 2009
    / Reply

    Marko,
    Great tutorial! I was looking for a prebuilt rss parser, so thanks!

    Also, you had a mistake in your code (the zip file) that I’d thought I’d point out. In the function parser you had the variable “entry”, instead of “feedItem” in the link for “Continue Reading”. It seems you flip back and forth between them in your code in the tutorial also.

    If you change the variable to “feedItem” everything works perfectly. Thanks!!

    1. / Reply

      You’re welcome, Joel! :)
      Thanks for pointing out the errors. I’ll correct the files and the code in the tutorial.

  4. / Reply

    Nice post, but since I’m not so familiar with PHP and my Tumblr doesn’t allow me to display recent posts, I headed over to Google’s Feed AJAX API and learned how to read in an RSS feed and used some Javascript to write it to my blog. It does it completely client-side, so its an alternative solution to PHP.

  5. / Reply

    Hi, a nice little example however I do have a couple of suggestions/comments (hence my commenting).

    You can avoid the issue of the functions.php include pushing the content down simply by putting it at the top of the page, before the HTML content. That way you can avoid using the extra div.

    One thing to beware of is that some shared hosts set a PHP config variable ‘allow_url_fopen’ to false to make their hosting more secure. If it’s false you won’t be able to open URLs and I believe this holds true in simplexml_load_file.

    Hope that helps if anyone’s been having strange problems,

    Jon

    1. / Reply

      Hi Jonathan, thanks for posting the comment.
      I have tried putting the PHP block at the top of the code, I have tried moving it all around the page, but it still pushes down the content in Safari and Chrome. I have found a few other positions for the PHP block where it doesn’t mess up the layout when viewed in Firefox but I’ve wanted to make it look good cross-browser, so the extra DIV seems like the best solution to me.
      Thanks for pointing out the possible problem with the ‘allow_url_fopen’ variable.

      1. / Reply

        Thanks Marko, I’ve never come across that before but I’ll keep an eye out for it now. Do you use Windows or Mac or Linux?

        1. / Reply

          You’re welcome! :)
          I’m a Windows user, how about you?

          1. /

            Windows all the way, can’t stand OSX and the hardware is ridiculously expensive. Currently badgering my boss to get me a Mac Mini though so I can test on it properly – VMs and Screenshots just aren’t the same.

          2. /

            I haven’t had a chance to play with OSX but you are right, Macs are quite pricey. I hope you get that Mac Mini soon, though. ;)

    • Fynn,
    • December 26, 2009
    / Reply

    Nice tut:)

    I have one question however, how can I see the xml structure of a link loaded via xml_load_file? Cant figure that out. Thanks in advance!

    1. / Reply

      Thanks, Fynn. :)
      Not sure what you mean, but you can open the XML file from an editor, like Notepad++. Just go to File -> Open, enter the URL of the RSS feed and you’ll be able to view the XML file. I hope that helps you…

        • Fynn,
        • December 26, 2009
        / Reply

        Thanks for the reply Marko. Very helpful, I didn’t know it was possible to open a feed link via an IDE.

        While I’m at it, I was wondering if you could give me some tips considering the following;

        Currently I try to fetch a huge feed which takes about 30 seconds to load and occasionally gives me a time out error. My idea was to fetch the feed via a script the visitor can’t access, doing this with time intervals to avoid the time out error. I want to save the data in several array’s which I will save in a several text files using the serialize/unserialize function. Finally I will run this script every hour using a cron job to make sure the data stays up to date.

        Is this a good solution? Do you have some tips or suggestions?

        Thanks again :)

        1. / Reply

          You’re quite welcome. :)
          Fynn, I don’t know if you’ve read Brant’s comment above, but I can only repeat his suggestion to use SimplePie. I think that it already does everything that you want to achieve plus some other stuff you might find useful. Give it a try, it could save you some time. ;)

  6. / Reply

    Awesome tutorial :) Helped me out greatly on one of my projects :) Thank you again and Happy Holidays!!!

    1. / Reply

      You’re welcome, I’m glad it was of help to you. :)

      Happy Holidays! :D

    • Damian,
    • December 28, 2009
    / Reply

    Great tutorial ;)

    1. / Reply

      Thanks, Damian! Glad you liked it. :)

  7. / Reply

    You can also use the open source Magpie RSS feed parser to parse RSS feeds in PHP!

  8. / Reply

    Thx for sharing, I’ve already implemented this in my blog.

    1. / Reply

      Cool, I’m glad you found it useful! :)

  9. / Reply

    Very useful tut. Big thanks

    • zami,
    • June 14, 2010
    / Reply

    great job marko, kindly release part2 for this tutorial to concentrate on speed, compatibility issues. thanks for great work/tutorial. i have saved it and like to share with my friends.

    thanks

  10. / Reply

    Great tutorial Marko. Couldn’t have asked for anything simpler. Do hope that you do a follow-up post on using SimplePie.

    1. / Reply

      Thank you so much. :)

      I am afraid that we have different plans for future posts so probably no SimplePie posts anytime soon.

      You should check out the documentation over at the SimplePie site as it’s pretty straightforward and it should be a breeze to implement SimplePie into your projects since you’ve already read this post and are familiar with the process. ;)

    • Ricardo Botha,
    • July 13, 2010
    / Reply

    Good Day,

    I just stumbled upon your site and thought I would ask.
    Is it possible to create a RSS Feed to update when website content updates.

    I run Ubuntu Linux on several of my machines and use uTorrent to download the latest releases.
    uTorrent has the ability to download RSS Feed items and I was thinking is it possible to get something that watches http://releases.ubuntu.com and all sub-folders for files that contain ubuntu-*-desktop-i386.iso.torrent so that uTorrent can download the torrents as they are released.
    And have the RSS Feed to publish to my Blog for friends to get access to the latest torrents without having to go to the Ubuntu website all the time?

    I have no prior knowledge of creating an RSS Feed than what I just read here and don’t even know if it is possible.

    1. / Reply

      Hi Ricardo,

      I am wondering if someone hadn’t already made an RSS feed for Ubuntu releases. :)

      I suppose that it is possible to monitor the Ubuntu Releases site with PHP, pick up on new additions and then update an RSS feed with those. My knowledge of PHP isn’t that great so I am afraid that you’d have better luck poking around some forums. Here is a very basic RSS tutorial to get you acquainted with its structure: http://www.xul.fr/en-xml-rss.html.

      Sorry I couldn’t be of more help.

    • Andy,
    • June 7, 2011
    / Reply

    great tutorial explains a little of every thing as a server side based site i have been trying to implement an rss reader into a site im making but i will be using multiple rss feeds how would i sort them by time and date ?

  11. / Reply

    Hi
    I just wanna say such type of tutorial make learning simple,easy and too fast.
    This is a very well written tutorial that having rich content and best representation of those.
    Thanking you.
    Keep it up high.
    Cheers!!!!!!!

    • Aneeq,
    • April 23, 2012
    / Reply

    There are several ways to read RSS feed in PHP, but this one is surely one of the easiest.

    channel->item as $entry) {
    echo “< a href="'$entry-" rel ="nofollow">link’ title=’$entry->title’>” . $entry->title . ““;
    }

    ?>

    Source:
    http://phphelp.co/2012/04/23/how-to-read-rss-feed-in-php/
    OR
    http://addr.pk/a0401

  12. / Reply

    This is so totally awesome! I appreciate all the work that went into making the demo files. I used them to put up a page for my club:
    http://westerndressageofkansas.org/

  13. / Reply

    Is there a way to disable the links in the rss feed to not allow link backs? I read about the ‘allow_url_fopen’ mentioned above. Is there anywhere I can put in a code to disable the links. I am using dreamweaver 6 as my editing program as I create my new site. I want to have the rss feeds without links.
    Thanks, Bob.

    • duniavern,
    • March 5, 2013
    / Reply

    thanks marco,
    your tutorial very help me finish my project

    i have question, if i want to show images from rss
    how to do that?

Leave a Reply

Your email address will not be published. Required fields are marked *

Deals