PHP
  Home arrow PHP arrow Page 4 - Rockin’ RSS with PHP on your HTML
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
PHP

Rockin’ RSS with PHP on your HTML
By: Danny Wall
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 39
    2004-11-23


    Table of Contents:
  • Rockin’ RSS with PHP on your HTML
  • An idea that's catching on
  • How--and why--to get started
  • Starting with the header
  • Adding content
  • Tease the reader

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Rockin’ RSS with PHP on your HTML - Starting with the header
    ( Page 4 of 6 )

    In fact, using the magic bag of tricks known as PHP, your own RSS file can be automatically created with very little effort, and once the PHP script is finished, the whole thing is “maintenance/management free.” 

    To provide a little further clarification, we’re going to cover the basics of RSS file creation (indeed, the example file I gave you above is only a basic RSS document).  In future articles we’ll talk about other elements to the RSS specification, what they mean, and why you might want to use them (and I’ll provide you the additions to the PHP script you’ll get in this article to add those elements).

    For nearly every website, some of the information in the RSS file--lets call it the “header” info--will be the same/static each time the file is created. That info is:

    <?xml version='1.0' ?>
    <rss version='2.0'>
    <channel>
    <title>Wolf Data News</title>
    <link>http://www.wolfdatasystems.com/</link>
    <description>News for programmers, business, and home computer users.</description>
    <language>en-us</language>
    <docs>http://www.wolfdatasystems.com/rss.xml</docs>

    As you can see, this amounts to the very first group of information in the file; and obviously you’ll want your own titles, your own links, and your own “feed description,” but the above will almost certainly be static information in your feed.  Every day when my site updates the RSS file, this information is unchanged.

    Now, lets go into building the PHP script to create the RSS file.  For the sake of discussion, lets call this file create_rss.php: 

    <?php
    // open a file pointer to an RSS file
    $fp = fopen ("rss.xml", "w");

    // Now write the header information
    fwrite ($fp, "<?xml version='1.0' ?><rss version='2.0'><channel>”);

    fwrite ($fp, “<title>Wolf Data News</title>");

    fwrite ($fp, "<link>http://www.wolfdatasystems.com/</link>");

    fwrite ($fp, "<description>News for programmers, business, and home computer users.</description>");

    fwrite ($fp, "<language>en-us</language>");

    fwrite ($fp, "<docs>http://www.wolfdatasystems.com/rss.xml</docs>");

    So far, we haven’t done anything too challenging. All we’ve done is opened a file, and written the header information that won’t be changing from file creation to file creation. 

    As you can see, I have broken the header file writes into several pieces. I’ve done this simply to make the script easier to see instead of having stuff trailing off to the right side of notepad forever. It isn’t at all necessary, but I do recommend it simply to make it easier to modify the file in the future.



     
     
    >>> More PHP Articles          >>> More By Danny Wall
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT