国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php ajax異步讀取rss文檔數(shù)據(jù)

Original 2017-01-06 11:36:44 243
abstract:RSS(Really Simple Syndication)是一種描述和同步網(wǎng)站內(nèi)容的格式,是使用最廣泛的XML應(yīng)用。RSS搭建了信息迅速傳播的一個(gè)技術(shù)平臺(tái),使得每個(gè)人都成為潛在的信息提供者。本文實(shí)例為大家分享了php ajax異步讀取rss文檔數(shù)據(jù)的相關(guān)代碼,供大家參考,具體內(nèi)容如下代碼如下:index.html<html>    <head> &nb

RSS(Really Simple Syndication)是一種描述和同步網(wǎng)站內(nèi)容的格式,是使用最廣泛的XML應(yīng)用。RSS搭建了信息迅速傳播的一個(gè)技術(shù)平臺(tái),使得每個(gè)人都成為潛在的信息提供者。

本文實(shí)例為大家分享了php ajax異步讀取rss文檔數(shù)據(jù)的相關(guān)代碼,供大家參考,具體內(nèi)容如下

代碼如下:

index.html

<html>
 
 <head>
  <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>
 </head>
 <body>
  <p>Please Select an option to get RSS:</p> 
  <form>
   <SELECT onchange="showRSS(this.value)">
   <option value="">Select an RSS-feed:</option>
   <option value="cnn">CNN</option>
   <option value="bbc">BBC News</option>
   <option value="pc">PC World</option>
   </SELECT>
  </form>
  <br> 
  <div id="output">RSS-feeds</div> 
 </body>
</html>

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("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>");
 echo("<br>");
 echo($channel_desc . "</p>");
 $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 ("<p><a href='" . $item_link . "'>" . $item_title . "</a>");
  echo ("<br>");
  echo ($item_desc . "</p>");
 }
?>

 更多關(guān)于php ajax異步讀取rss文檔數(shù)據(jù)請關(guān)注PHP中文網(wǎng)(www.miracleart.cn)其他文章!  



Release Notes

Popular Entries