📜  PHP-Ajax RSS Feed示例

📅  最后修改于: 2020-10-25 14:48:14             🧑  作者: Mango


的RSS

真正简单的联合组织用于发布网站上经常更新的信息,例如音频,视频,图像等。我们可以使用Ajax和php将RSS feed集成到网站。此代码演示了如何在我们的网站中显示RSS feed。

Index.html

索引页应如下-


      
   
   
   
      

Please Select an option to get RSS:


RSS-feeds

rss.php

rss.php包含有关如何访问rss提要并将rss提要返回到网页的语法。

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 . "

"); } ?>

它将产生以下结果-

RSS Feed示例