HomeXML Page 3 - Creating an RSS Reader Application
Parsing the 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.
The next function just parses the RSS document that is allocated it.
function showparsedContents($thelocation){ parsefile($thelocation); }
When the "Create RSS document" link is selected, a function called choicefrm() is activated. This function displays a form that requests a name for the RSS document that you want to create, and also requests that you choose between a simple RSS document or an enhanced one.
Fig 2. A form that request what type of RSS document to create...
Then based on your choice, one of the two forms are displayed. Now, let's say you chose a simple version. A function called simplefrm() will be activated which will request that you enter the required information. Here's a screen shot:
Fig 3. Simple RSS Document information form...
When you submit the form, the do_simpfrm() function is called, which processes the form variables and then creates the RSS document. Here's the function that does all that:
function do_simpfrm($filename,$mtitle,$mlink,$mdesc,$t1,$l1, $txt1,$t2,$l2,$txt2,$t3,$l3,$txt3){
//Create the file if($fp = fopen($filename,"a+")){ //write in the file 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,"<item>rn"); fwrite($fp,"<title>".$t1."</title>rn"); fwrite($fp,"<link>".$l1."</link>"); 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,"<item>rn"); fwrite($fp,"<title>".$t3."</title>rn"); fwrite($fp,"<link>".$l3."</link>rn"); fwrite($fp,"<description>".$txt3."</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"; } }