Home arrow PHP arrow Page 3 - Plugging RDF Content Into Your Web Site With PHP

Switching Channels - PHP

A Web site which dynamically updates itself with the latestnews and information? Nope, it's not as far-fetched as it sounds. Asthis article demonstrates, all you need is a little imagination, acouple of free RDF files and some PHP glue.

TABLE OF CONTENTS:
  1. Plugging RDF Content Into Your Web Site With PHP
  2. Have Content, Will Syndicate
  3. Switching Channels
  4. Fresh Meat
  5. Capture The Flag
  6. Nesting Time
  7. Back To Class
  8. Adding A Little Style
  9. Homework
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 19
February 27, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
An RSS document typically contains a list of resources (URLs), marked up with descriptive metadata. Here's an example:

<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/"> <channel rdf:about="http://www.melonfire.com/"> <title>Trog</title> <description>Well-written technical articles and tutorials on Web technologies</description> <link>http://www.melonfire.com/community/columns/trog/</link> <items> <rdf:Seq> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =100" /> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =71" /> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =62" /> </rdf:Seq> </items> </channel> <item rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i d=10 0"> <title>Building A PHP-Based Mail Client (part 1)</title> <link>http://www.melonfire.com/community/columns/trog/article.php?id=100 </li nk> <description>Ever wondered how Web-based mail clients work? Find out here.</description> </item> <item rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i d=71"> <title>Using PHP With XML (part 1)</title> <link>http://www.melonfire.com/community/columns/trog/article.php?id=71< /link> <description>Use PHP's SAX parser to parse XML data and generate HTML pages.</description> </item> <item rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i d=62"> <title>Access Granted</title> <link>http://www.melonfire.com/community/columns/trog/article.php?id=62< /link> <description>Precisely control access to information with the mySQL grant tables.</description> </item> </rdf:RDF>
As you can see, an RDF file is split up into very clearly-demarcated sections. First comes the document prolog,

<?xml version="1.0" encoding="UTF-8"?>
and namespace declarations in the root element.

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/">
This is followed by a <channel> block, which contains general information on the channel that is described by this RDF file. In the example above, the channel is Melonfire's Trog column, which gets updated every week with new technical articles and tutorials.

<channel rdf:about="http://www.melonfire.com/"> <title>Trog</title> <description>Well-written technical articles and tutorials on Web technologies</description> <link>http://www.melonfire.com/community/columns/trog/</link> <items> <rdf:Seq> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =100" /> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =71" /> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =62" /> </rdf:Seq> </items> </channel>
The <channel> block contains an <items> block, which contains a sequential list of all the resources described within the RDF document. This list is formulated as a series of <li /> elements, which may be familiar to you from HTML. Every resource in this block corresponds to a resource described in greater detail in a subsequent <item> block (further down).

<items> <rdf:Seq> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =100" /> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =71" /> <li rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph p?id =62" /> </rdf:Seq> </items>
It's also possible to intersperse an <image> block at this stage, in case you'd like to publish the URL of your channel's logo.

And now for the meat. Every <item> block in an RSS 1.0 document describes a single resource in greater detail, providing a title, a URL and a description of that resource.

<item rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i d=71"> <title>Using PHP With XML (part 1)</title> <link>http://www.melonfire.com/community/columns/trog/article.php?id=71< /link> <description>Use PHP's SAX parser to parse XML data and generate HTML pages.</description> </item>
In this example, the <item> block above describes a single article in the Trog "channel", providing a description and title for it, and including a URL so that a content aggregator can create backward links to it.

As you can see, an RSS 1.0 file is fairly straightforward, and it's quite easy to create one, either manually or programmatically. The example and explanation above was merely illustrative; there's a lot more you can do with RSS 1.0 and RDF in general, and you should take a look at the links provided at the end of this article for more information. Until we get there, though, let's spend a few more minutes discussing how an RSS 1.0 document like the one above can be plugged into your own Web site.

 
 
>>> More PHP Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap

Dev Shed Tutorial Topics: