The RSS reader is used to read the RSS feed, which is the basis of this tutorial.
Example explanation-HTML page
When the user selects a rss-feed in the drop-down list above, a function named "Showrss ()" is executed. This function is triggered by the "onchange" event:
The Showrss () function performs the following steps:
Check if any rss-feed are selected
Create a XMLHttpRequest Object
Create a function that executes when the server responds ready
Send a request to a file on the server
Note the parameter (q) added to the end of the URL (contains the contents of the drop-down list)
PHP file
File Rss_demo.xml.
The above server page that is called by JavaScript is a php file named "getrss.php":
<?php//rss file $xml= "Rss_demo.xml"; $xmlDoc = new DOMDocument (); $xmlDoc->load ($xml);//Read element from ' <channel> ' channel= $xmlDoc->getelementsbytagname (' channel ')->item (0); $channel _title = $channel getElementsByTagName (' title ')->item (0)->childnodes->item (0)->nodevalue; $channel _link = $channel getElementsByTagName (' link ')->item (0)->childnodes->item (0)->nodevalue; $channel _desc = $channel getElementsByTagName (' description ')->item (0)->childnodes->item (0)->nodevalue;//output "<channel>" The element in Echo ("<p><a href="). $channel _link. ">". $channel _title. "</a>"), Echo ("<br>"), Echo ($channel _desc. "</p>");//output "<item>" element $x= $xmlDoc->getelementsbytagname (' item '); for ($i =0; $i <=1; $i + +) {$item _ title= $x->item ($i)->getelementsbytagname (' title ')->item (0)->childnodes->item (0)->nodevalue; $item _link= $x->item ($i)->getelementsbytagname (' link ')->item (0)->chIldnodes->item (0)->nodevalue; $item _desc= $x->item ($i)->getelementsbytagname (' description ')->item (0)->childnodes->item (0) NodeValue; Echo ("<p><a href=". $item _link. ">". $item _title. "</a>"); Echo ("<br>"); Echo ($item _desc. "</p>");}? >
When a request for an RSS feed is sent from JavaScript to a PHP file, it occurs:
Check which RSS feed is selected
To create a new XML DOM object
Loading an RSS document in an XML variable
Extracting and outputting elements from the channel element
Extracting and outputting elements from the item element
This article on the Ajax RSS reader of the relevant knowledge points are explained, more learning materials clear focus on the PHP Chinese network can be viewed.