Creating an RSS Reader: the Reader (Page 1 of 4 )
In this article we are going to discuss how to create a PHP-based RSS reader. It would be helpful if you know something about XML, but not really necessary. RSS documents have three main tags: Title, Link and Description. And they all do exactly what their names suggest. I will go into detail about these tags in my second article dealing with “building an RSS file.” For now, we will only focus on the “reading” part of the article.
A
downloadable file is available for this article.
As an extra I will introduce a database aspect of the reader. We will use the database to store and retrieve the latest stories. To continue with this article you will need PHP 4 and higher and optionally MYSQL.
Below is an example text from an RSS document:
Start example text
<item>
<title>First example</title>
<link>www.mylink.com/someplace.html</link>
<description>Some description, blah,blah,blah
</description>
</item>
<item>
<title>Thousands set to attend todays celebration</title>
<link>http://
www.mylink.com/someplace.html /NewsTopStories?m=318</link>
<description>blah,blah,blah </description>
</item>
End example text
Code
To create an RSS Reader in PHP, we need to:
- Create a function to read the start tag (start element).
- Create a function to read the end tag (endElement).
- Create function to read the text associated with the tags.
A typical RSS document will have the following structure:
<RSS>
<channel>
<item>
</item>
</channel>
</RSS>
A start tag is a tag without the “/” character, for example: <items>. An end tag is a tag with the “/” character, for example: </item>.
So the start and end tag functions will search for the “<item></item>” tags and once they have found those, it will be a simple matter of retrieving the text data from them to display.
Next: XML-related Functions >>
More MySQL Articles
More By Jacques Noah