Saturday, December 26, 2009

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.

RSS Feed Parser

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.



MORE

0 comments: