Logo         Community
The Company
Your Account
Contact Us
PHP 101 (part 15): No News is Good News
Build your own personal RSS aggregator with PHP, SimpleXML and SQLite

| Laying the Foundation |

Now that you know what RSS and RDF are all about, it's time to start work. I'll begin by sitting down at a table near the window and doodling aimlessly on a sheet of paper until I figure out exactly what my application is supposed to do, piece by piece (actually, in this case, the requirements are actually pretty basic):

1. The application must support one or more RSS-compliant news feeds. On start-up, the application should retrieve the latest versions of these feeds, parse them and display their contents in an easy-to-read manner. A SQLite database is a good choice to store this list of feeds.

2. The user should be able to control the number of stories s/he picks up from each feed. For example, a user might want to display more science and health news than business news.

3. The application should offer the user a web-based interface to add or delete news feeds. This interface will use PHP's SQLite API to run appropriate SQL queries on the SQLite database file and alter the information stored in the database.

Keeping these requirements in mind, it's possible to design a simple database table to hold the (user-configurable) list of RSS news feeds. Here's what it might look like:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
  title varchar(255) NOT NULL,
  url varchar(255) NOT NULL,

From the table above, it's clear that every news feed will have three attributes: a descriptive title, the URL to the feed itself, and a value indicating how many of the stories in the feed you would like to see displayed in your own custom news page.

Let's add some data to get things started:

''.preg_replace(array('/  /', '/ /'), array('  ', '   '), '
INSERT INTO rss VALUES(1, 'Slashdot', 'http://slashdot.org/slashdot.rdf', 5);
INSERT INTO rss VALUES(2, 'Wired News', 'http://www.wired.com/news_drop/netcenter/netcenter.rdf', 5);
INSERT INTO rss VALUES(3, 'Business News', 'http://www.npr.org/rss/rss.php?topicId=6', 3);
INSERT INTO rss VALUES(4, 'Health News', 'http://news.bbc.co.uk/rss/newsonline_world_edition/health/rss091.xml', 3);
INSERT INTO rss VALUES(5, 'Freshmeat', 'http://www.freshmeat.net/backend/fm-releases.rdf', 5);

You can create all this directly from the schema file rss.sql using the SQLite command-line tool. In fact, now would be a good time for you to download all the source code for this application, so that you can check it out and refer to it easily throughout this tutorial. Note that you will need a PHP 5-enabled web server to run this code.

Download now!

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback