时间:2021-07-01 10:21:17 帮助过:3人阅读
本文实例为大家分享了php ajax异步读取rss文档数据的相关代码,供大家参考,具体内容如下
代码如下:
index.html
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("
"); $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 ("
"); echo($channel_desc . "" . $item_title . ""); echo ("
"); } ?>
"); echo ($item_desc . "
以上就是本文的全部内容,希望对大家学习php程序设计有所帮助。