php ajax異步讀取rss文檔數(shù)據(jù)
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>"); } ?>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。
- 用PHP讀取RSS feed的代碼
- PHP 正則表達(dá)式分析RSS
- PHP調(diào)用Twitter的RSS的實(shí)現(xiàn)代碼
- php中通過(guò)Ajax如何實(shí)現(xiàn)異步文件上傳的代碼實(shí)例
- php XMLWriter類的簡(jiǎn)單示例代碼(RSS輸出)
- 利用ThinkPHP內(nèi)置的ThinkAjax實(shí)現(xiàn)異步傳輸技術(shù)的實(shí)現(xiàn)方法
- PHP+Ajax異步通訊實(shí)現(xiàn)用戶名郵箱驗(yàn)證是否已注冊(cè)( 2種方法實(shí)現(xiàn))
- Ajax異步傳輸與PHP實(shí)現(xiàn)交互示例
- PHP curl 抓取AJAX異步內(nèi)容示例
- php生成RSS訂閱的方法
相關(guān)文章
php+ajax無(wú)刷新上傳圖片的實(shí)現(xiàn)方法
這篇文章主要介紹了php+ajax無(wú)刷新上傳圖片的實(shí)現(xiàn)方法,涉及php結(jié)合ajax進(jìn)行文件傳輸操作相關(guān)技巧,需要的朋友可以參考下2016-12-12PHP生成指定范圍內(nèi)的N個(gè)不重復(fù)的隨機(jī)數(shù)
今天小編就為大家分享一篇關(guān)于PHP生成指定范圍內(nèi)的N個(gè)不重復(fù)的隨機(jī)數(shù),小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03利用PHP如何實(shí)現(xiàn)Socket服務(wù)器
想要構(gòu)建聊天應(yīng)用,或者甚至是游戲嗎?那么,socket服務(wù)器將成為你邁出的第一步。一旦你了解了創(chuàng)建服務(wù)器的基本功能,那么后續(xù)的優(yōu)化步驟就會(huì)變得同樣簡(jiǎn)單,需要的朋友可以參考下2015-09-09php結(jié)合web uploader插件實(shí)現(xiàn)分片上傳文件
這篇文章主要為大家詳細(xì)介紹了php結(jié)合web uploader插件實(shí)現(xiàn)分片上傳文件, 采用大文件分片并發(fā)上傳,極大的提高了文件上傳效率,感興趣的小伙伴們可以參考一下2016-05-05PHP嚴(yán)重致命錯(cuò)誤處理:php Fatal error: Cannot redeclare class or funct
這篇文章主要介紹了PHP嚴(yán)重致命錯(cuò)誤處理:php Fatal error: Cannot redeclare class or function,需要的朋友可以參考下2017-02-02windows中PHP5.2.14以及apache2.2.16安裝配置方法
windows中PHP5.2.14以及apache2.2.16安裝配置,需要配置php運(yùn)行環(huán)境的朋友可以參考下。2010-09-09