XML Tutorials
  Home arrow XML Tutorials arrow Page 3 - Creating RSS 2.0 Feeds
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML TUTORIALS

Creating RSS 2.0 Feeds
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-17

    Table of Contents:
  • Creating RSS 2.0 Feeds
  • guid, Permalink or not
  • Creating RSS 2.0 with PHP
  • Caching and saving

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating RSS 2.0 Feeds - Creating RSS 2.0 with PHP


    (Page 3 of 4 )

    Great RSS 2.0 support for PHP is to be found in the feedcreator.class by Kai Blankenhorn at http://www.bitfolge.de. Unlike the previous section's XML::RSS, feedcreator.class can only create RSS feeds; it can't parse them. No matter: it's very good at that indeed.

    As illustrated in Example 4-10, the function for each feed element is named after the element, so it behaves pretty much as you would expect.

    Example 4-10. A PHP script using FeedCreator that produces RSS 2.0

    <?php
    include("feedcreator.class.php");

    $rss = new UniversalFeedCreator();
    $rss->title = "Example Feed";
    $rss->description = "This is the feed description";
    $rss->link = "http://www.example.com/";

    // Image section
    $image = new FeedImage();
    $image->title = "example logo";
    $image->url = "http://www.example.com/images/logo.gif"; $image->link = "http://www.example.com"; $image->description = "Visit Example.com!"; $rss->image = $image;

    // Item Loop
    $item = new FeedItem();
    $item->title = "Entry one";
    $item->link = http://www.example.com/entryone;
    $item->description = "This is the content of the first entry";
    $item->author = "Ben Hammersley";
    $rss->addItem($item);
    // End Item Loop

    ?>

    This is a very simple script. As you can see from the resulting feed, Example 4-11, it produces only one item. We'll be using it for more complicated things later on in the book, so in the meantime, once we've passed over the example output, we'll take a quick look at some of the special features.

    Example 4-11. An RSS 2.0 feed created with PHP

    <?xml version="1.0" encoding="ISO-8859-1"?> <!-- generator="FeedCreator 1.7.1" -->
    <rss version="2.0">
       
    <channel>
            <title>Example Feed</title>
            <description>This is the feed description</description>
            <link>http://www.example.com/</link>
            <lastBuildDate>Thu, 16 Sep 2004 20:16:22 +0100</lastBuildDate>
            <generator>FeedCreator 1.7.1</generator>
            <image> 

                <url>http://www.example.com/ images/logo.gif</url>
                <title>example logo</title> 
                <link>http://www.example.com </link>
                <description>Visit Example.com!</description>
            </image>
           
    <item>
                <title>Entry one</title> 
                <link>http://www.example.com/ entryone</link>
                <description>This is the content of the first entry</description>
                <author>Ben Hammersley</author>
           
    </item>
        </channel>
    </rss>

    More XML Tutorials Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Developing Feeds with RSS and Atom,"...
     

    Buy this book now. This article is excerpted from chapter four of the book Developing Feeds with RSS and Atom, written by Ben Hammersley (O'Reilly; ISBN: 0596008813). Check it out today at your favorite bookstore. Buy this book now.

    XML TUTORIALS ARTICLES

    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway