Hardware Reference
In-Depth Information
News
Any data that changes is new, and therefore news, making it an ideal candidate for real-time access. Making a
personalized news channel is something most aggregators are doing through the use of RSS feeds and custom
widgets. The soon to be retired iGoogle ( www.google.com/ig ), for example, also includes integration with its Google
Mail and Calendar services, making this a disturbingly useful home page when viewed as a home page, but its
enclosed nature makes it difficult to utilize this as a data input for a home. Instead, I'll cover methods to retrieve
typical news items as individual data elements, which can be incorporated in a manner befitting ourselves. This splits
into two types: push and pull.
Reported Stories: Push
The introduction of push-based media can be traced either to 24-hour rolling news (by Arthur W. Arundel in 1961) or
to RSS 9 feeds, depending on your circumstances. Both formats appear to push the information in real time, as soon
as it's received, to the viewer. In reality, both work by having the viewer continually pull data from the stream, silently
ignoring anything that hasn't changed. In the case of TV, each pull consists of a new image and occurs several times a
second. RSS happens significantly less frequently but is the one of interest here.
RSS Feeds
RSS is an XML-based file format for metadata. It describes a number of pieces of information that are updated
frequently. This might include the reference to a blog post, the next train to leave platform 9¾ from King's Cross,
the current stories on a news web site, and so on. In each case, every change is recorded in the RSS file, along with the
all-important time stamp, enabling RSS readers to determine any updates to the data mentioned within it. The software
that generates these RSS feeds may also remove references to previous stories once they become irrelevant or too old.
However, old is defined by the author.
This de facto standard allows you to use common libraries to parse the RSS feeds and extract the information
quite simply. One such library is the PHP-based MagpieRSS ( http://magpierss.sourceforge.net ), which also
supports an alternative to RSS called Atom feeds and incorporates a data cache. This second feature makes your code
simpler as you can request all the data from the RSS feed, without a concern for the most recent, because the library
has cached the older stories automatically.
You utilize MagpieRSS in PHP by beginning with the usual code:
require_once 'rss_fetch.inc';
Then you request a feed from a given URL:
$rss = fetch_rss($url);
Naturally, this URL must reference an RSS file (such as www.thebeercrate.com/rss_feed.xml ) and not the page
that it describes (which would be www.thebeercrate.com ). It is usually indicated by an orange button with white radio
waves or simply an icon stating “RSS-XML.” In all cases, the RSS file appears on the same page whose data you want to
read. You can the process the stories with a simple loop such as the following:
$maxItems = 10;
$lastItem = count($rss->items);
233 CURRENTLYSTANDSFOR2EALLY3IMPLE3YNDICATIONBUTITSLONGANDINTERESTINGHISTORYMEANSTHATITWASNȀTALWAYSSOSIMPLE
Search WWH ::




Custom Search