JavaScript Editor Ajax software     Free javascripts 



Main Page

The description can hold any content you wish, including XHTML.
</description>
<pubDate>Tue, 12 Sep 2006 07:56:23 EDT</pubDate>
</item>
<item>
<title>Another Catchy Title</title>
<link>http://www.example.org/another-catchy-title.html</link>
<description>
The description can hold any content you wish, including XHTML.
</description>
<pubDate>Tue, 12 Sep 2006 07:56:23 EDT</pubDate>
</item>
</channel>
</rss>
The feed may contain any number of
<item>
elements, each item holding different news or blog entries —
or whatever content you want to store.
You can either create feeds for others to access, or you can syndicate feeds that others create. The follow-
ing section discusses how to create feeds, and the next demonstrates the use of a third-party library called
SimplePie to syndicate feeds.
Creating RSS Feeds
To make generating feeds for your content easier, create a class called the “
RSS Factory
.” For the first
time, you’ll use object-oriented programming (OOP).
Previous exercises avoided using PHP’s object-oriented programming support. It’s used for this one
because it actually makes things easier. Some explanations on its usage follow the exercise.
The class is aptly named
RSSFactory
, and it will provide all necessary functionality for generating RSS
feeds. You’ll implement this class and then use it to create a feed for “new SEO Egghead products” in the
exercise that follows.
Creating the RSS Factory
1.
Create a new file named
rss_factory.inc.php
in your
seophp/include
folder. You’ll keep
your RSS Factory class in this file. Type this code in
rss_factory.inc.php
:
<?php
class RSSFactory
{
var $_title;
var $_link;
var $_description;
var $_language;
var $_items;
// escape string characters for inclusion in XML structure
154
Chapter 7: Web Feeds and Social Bookmarking
c07.qxd:c07 10:42 154


JavaScript Editor Ajax software     Free javascripts