HomeXML 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.
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:
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.