Phpajax asynchronously reads rss document data ,. Phpajax asynchronously reads rss document data. RSS (ReallySimpleSyndication) is a format used to describe and synchronize website content. it is the most widely used XML application. RSS sets up php ajax for rapid information dissemination to asynchronously read rss document data,
RSS (Really Simple Syndication) is a format used to describe and synchronize website content. it is the most widely used XML application. RSS builds a technical platform for rapid dissemination of information, making everyone a potential information provider.
The example in this article shares the code for asynchronously reading rss document data from php ajax for your reference. The details are as follows:
The code is as follows:
Index.html
《script》 function showRSS(str) { if (str.length==0) { document.getElementById("output").innerHTML=""; return; } if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("output").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","rss.php?q="+str,true); xmlhttp.send(); } 《script》 Please Select an option to get RSS:
RSS-feeds
Rss. php
<?php $q=$_GET["q"]; if($q=="cnn") { $xml=("http://rss.cnn.com/rss/cnn_topstories.rss"); } elseif($q=="bbc") { $xml=("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/americas/rss.xml"); } elseif($q="pcw"){ $xml=("http://www.pcworld.com/index.rss"); } $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); $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; echo("" . $channel_title . ""); echo("
"); echo($channel_desc . "
"); $x=$xmlDoc->getElementsByTagName('item'); for ($i=0; $i<=2; $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 ("" . $item_title . ""); echo ("
"); echo ($item_desc . "
"); }?>
The above is all the content of this article. I hope it will help you learn php programming.
Articles you may be interested in:
- Use PHP to read the RSS feed code
- PHP regular expression analysis RSS
- PHP calls Twitter's RSS implementation code
- Code example for asynchronous file upload using Ajax in php
- Simple sample code of the php XMLWriter class (RSS output)
- Implementation of asynchronous transmission technology using ThinkPHP's built-in ThinkAjax
- PHP + Ajax asynchronous communication implements user name email verification (two methods)
- Example of interaction between Ajax asynchronous transmission and PHP
- Example of AJAX asynchronous content captured by PHP curl
- Methods for generating RSS subscriptions using php
Http://www.bkjia.com/PHPjc/1117074.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1117074.htmlTechArticlephp ajax asynchronously reads rss document data, RSS (Really Simple Syndication) is a format that describes and synchronizes website content, is the most widely used XML application. RSS sets up the rapid dissemination of information...