Home arrow XML arrow Page 4 - Creating an RSS Reader Application

Creating an enhanced RSS document - XML

In the previous two articles we discussed how to read and build an RSS document with PHP. In this article we will create an application that uses the concepts discussed in the other two articles. So letís go straight to the coding.

TABLE OF CONTENTS:
  1. Creating an RSS Reader Application
  2. Code
  3. Parsing the RSS document
  4. Creating an enhanced RSS document
By: Jacques Noah
Rating: starstarstarstarstar / 14
February 20, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

If your choice was to create an Enhanced version, a function called efrm() is called which displays a form that requests particular info from you. Below is a screen shot of the form and after that is shown the actual function code:

Fig 4. Enhanced RSS Document information form...

function enhancedfrm(){
 
echo '<form id="form1" name="form1" method="post"
action="' .$_SERVER['PHP_SELF'].'?action=efrm">
  
<table width="82%" border="0" cellspacing="1">
    <tr>
      <td colspan="4" valign="top" bgcolor="#999999"><strong>All
information on this form is required: </strong></td>
    </tr>
    <tr>
      <td valign="top"><strong>Title</strong></td>
      <td><input name="mtitle" type="text" size="40" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td valign="top"><strong>Link</strong></td>
      <td><input name="mlink" type="text" size="40" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td valign="top"><strong>Description</strong></td>
      <td><textarea name="mdesc" cols="40"
rows="5"></textarea></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td width="18%" bgcolor="#999999">&nbsp;</td>
      <td width="33%" bgcolor="#999999">&nbsp;</td>
      <td width="11%" bgcolor="#999999">&nbsp;</td>
      <td width="38%" bgcolor="#999999">&nbsp;</td>
    </tr>
    <tr>
      <td valign="top"><strong>Managing Editor: </strong></td>
      <td valign="top"><input name="me" type="text" id="me"
size="40" /></td>
      <td valign="top"><strong>URL:</strong></td>
      <td valign="top"><input name="imgURL" type="text"
id="imgURL" size="40" /></td>
    </tr>
    <tr>
      <td valign="top"><strong>Web Master: </strong></td>
      <td valign="top"><input name="wm" type="text" id="wm"
size="40" /></td>
      <td valign="top"><strong>Title:</strong></td>
      <td valign="top"><input name="imgTitle" type="text"
id="imgTitle" size="40" /></td>
    </tr>
    <tr>
      <td valign="top"><strong>Publication Date: </strong></td>
      <td valign="top"><input name="pubdate" type="text"
id="pubdate" size="40" /></td>
      <td valign="top"><strong>Link:</strong></td>
      <td valign="top"><input name="imgLink" type="text"
id="imgLink" size="40" /></td>
    </tr>
    <tr>
      <td valign="top"><strong>Last Build Date: </strong></td>
      <td valign="top"><input name="bdate" type="text" id="bdate"
size="40" /></td>
      <td valign="top"><strong>Width:</strong></td>
      <td valign="top"><input name="width" type="text" id="width"
size="30" /></td>
    </tr>
    <tr>
      <td valign="top"><strong>Generator:</strong></td>
      <td valign="top"><input name="gen" type="text" id="gen"
size="40" /></td>
      <td valign="top"><strong>Height:</strong></td>
      <td valign="top"><input name="height" type="text"
id="height" size="30" /></td>
    </tr>
    <tr>
      <td valign="top"><strong>Docs:</strong></td>
      <td valign="top"><input name="docs" type="text" id="docs"
size="40" /></td>
      <td valign="top">&nbsp;</td>
      <td valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td valign="top"><strong>CopyRight Notice: </strong></td>
      <td valign="top"><input name="cright" type="text"
id="cright" size="40" /></td>
      <td valign="top">&nbsp;</td>
      <td valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td valign="top"><strong>Language:</strong></td>
      <td valign="top"><input name="lang" type="text" id="lang"
size="40" /></td>
      <td valign="top">&nbsp;</td>
      <td valign="top">&nbsp;</td>
    </tr>
    <tr>
      <td bgcolor="#666666">&nbsp;</td>
      <td bgcolor="#666666">&nbsp;</td>
      <td bgcolor="#666666">&nbsp;</td>
      <td bgcolor="#666666">&nbsp;</td>
    </tr>
    <tr>
      <td><strong>Title:</strong></td>
      <td><input name="t1" type="text" id="t1" size="40" /></td>
      <td><strong>Title:</strong></td>
      <td><input name="t2" type="text" id="t2" size="40" /></td>
    </tr>
    <tr>
      <td><strong>Link:</strong></td>
      <td><input name="l1" type="text" id="l1" size="40" /></td>
      <td><strong>Link:</strong></td>
      <td><input name="l2" type="text" id="l2" size="40" /></td>
    </tr>
    <tr>
      <td valign="top"><strong>Description:</strong></td>
      <td><textarea name="d1" cols="40" rows="5"
id="d1"></textarea></td>
      <td valign="top"><strong>Description:</strong></td>
      <td valign="top"><textarea name="d2" cols="40" rows="5"
id="d2"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Submit" /></td>
      <td>&nbsp;</td>
    </tr>
  </table>';
echo '</form>';
}

Once you've submitted this form, the do_efrm function is called. The purpose of this function is to create the RSS document with the information that you supplied in the form. The function is shown below:

function do_efrm($filename,$mtitle,$mlink,$mdesc,$me,$wm,
$cright,$lang,$pubdate,$builddate,$gen,$docs,$imgurl,$imgtitle,
$imglink,$t1,$l1,$txt1,$t2,$l2,$txt2){
 
//Create the file
 
if($fp = fopen($filename,"a+")){
   
fwrite($fp,"<?xml version='1.0'?>rn");
   
fwrite($fp,"<rss version='2.0' >rn");
   
fwrite($fp,"<channel>rn");
   
fwrite($fp,"<title>".$mtitle."</title>rn");
   
fwrite($fp,"<link>".$mlink."</link>rn");
   
fwrite($fp,"<description>".$mdesc."</description>rn");
   
fwrite($fp,"<managingEditor>".
           $me."</mangagingEditor>rn");
   
fwrite($fp,"<webMaster>".$wm."</webMaster>rn");
   
fwrite($fp,"<copyright>".$cright."</copyright>rn");
   
fwrite($fp,"<language>".$lang."</language>rn");
   
fwrite($fp,"<pubdate>".$pubdate."</pubdate>rn");
   
fwrite($fp,"<lastbuilddate>".
           $builddate."</lastbuilddate>rn");
   
fwrite($fp,"<generator>".$gen."</generator>rn");
   
fwrite($fp,"<docs>".$docs."</docs>rn");
   
fwrite($fp,"<image>rn");
   
fwrite($fp,"<url>".$imgURL."</url>rn");
   
fwrite($fp,"<title>".$imgtitle."</title>rn");
   
fwrite($fp,"<link>".$imglink."</link>rn");
   
fwrite($fp,"</image>rn");
   
fwrite($fp,"<item>rn");
    
fwrite($fp,"<title>".$t1."</title>rn");
   
fwrite($fp,"<link>".$l1."</link>rn");
   
fwrite($fp,"<description>".$txt1."</description>rn");
   
fwrite($fp,"</item>rn");
   
fwrite($fp,"<item>rn");
   
fwrite($fp,"<title>".$t2."</title>rn");
   
fwrite($fp,"<link>".$l2."</link>rn");
   
fwrite($fp,"<description>".$txt2."</description>rn");
   
fwrite($fp,"</item>rn");
   
fwrite($fp,"</channel>rn");
   
fwrite($fp,"</rss>");
   
fclose($fp);
   
echo "The RSS document <b>" .$filename. "</b> has been created and stored.";
  
}else{
   
echo "The file could not be created due to a system error";
 
}
}

There you have it! You can now read and create as many RSS documents as you like!

Conclusion

Although this program fulfills its basic aim of creating RSS files, it nevertheless needs some improvements, especially in the area of checking submitted form data. This is important because you do not want to create files with no information. Also, I've not done a lot as far as the application design is concerned, because I only wanted to focus on the programming code as opposed to its design. But the building blocks are there for you to create the design to your taste.



 
 
>>> More XML Articles          >>> More By Jacques Noah
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: