php 生成RSS文件类实例代码

怪我咯
发布: 2017-07-11 16:35:15
原创
1356 人浏览过

RSS(简易信息聚合):是一种消息来源格式规范,用以发布经常更新数据的网站,例如博客文章、新闻、音频视频的网摘。RSS文件(或称做摘要、网络摘要、或频更新,提供到频道)包含了全文或是节录的文字,再加上发用者所订阅之网摘布数据和授权的元数据。网络摘要能够使发行者自动地发布他们的数据,同时也使读者能更够定期更新他们喜欢的网站或是聚合不同网站的网摘。RSS摘要可以借由RSS阅读器、feed reader或是aggregator等网页或以桌面为架构的软件来阅读。标准的XML档式可允许信息在一次发布后通过不同的程序阅览。用户借由将网摘输入RSS阅读器或是用鼠标点取浏览器上指向订阅程序的RSS小图标之URI(非通常称为URL)来订阅网摘。RSS阅读器定期检阅是否有更新,然后下载给监看用户界面。

RSS可以是以下三种解释中任一种的缩写,但其实这三者都是指同一种联合供稿(Syndication)的技术:

这篇文章主要介绍了PHP生成RSS文件类,可实现PHP生成RSS文件的功能,对于网站建设与优化来说具有一定的实用价值,需要的朋友可以参考下

PHP RSS 生成类实例代码如下:

 代码如下:

<?php 
if (defined(&#39;_class_rss_php&#39;)) return; 
define(&#39;_class_rss_php教程&#39;,1); 

class rss { 
   //public 
   $rss_ver = "2.0"; 
   $channel_title = &#39;&#39;; 
   $channel_link = &#39;&#39;; 
   $channel_description = &#39;&#39;; 
   $language = &#39;zh_cn&#39;; 
   $copyright = &#39;&#39;; 
   $webmaster = &#39;&#39;; 
   $pubdate = &#39;&#39;; 
   $lastbuilddate = &#39;&#39;; 
   $generator = &#39;redfox rss generator&#39;; 
 
   $content = &#39;&#39;; 
   $items = array(); 
 
   function rss($title, $link, $description) { 
       $this->channel_title = $title; 
       $this->channel_link = $link; 
       $this->channel_description = $description; 
       $this->pubdate = date(&#39;y-m-d h:i:s&#39;,time()); 
       $this->lastbuilddate = date(&#39;y-m-d h:i:s&#39;,time()); 
   } 
 
   function additem($title, $link, $description ,$pubdate) { 
       $this->items[] = array(&#39;titile&#39; => $title , 
                        &#39;link&#39; => $link, 
                        &#39;description&#39; => $description, 
                        &#39;pubdate&#39; => $pubdate); 
   } 
 
   function buildrss() { 
       $s = "<!--l version="1.0" encoding="gb2312"--> "; 
       // start channel 
       $s .= " "; 
       $s .= " " 
       $s .= "<link />{$this->channel_link} "; 
       $s .= "{$this->channel_description} "; 
       $s .= "{$this->language} "; 
       if (!emptyempty($this->copyright)) { 
          $s .= "{$this->copyright} "; 
       } 
       if (!emptyempty($this->webmaster)) { 
          $s .= "{$this->webmaster} "; 
       } 
       if (!emptyempty($this->pubdate)) { 
          $s .= "{$this->pubdate} "; 
       } 
 
       if (!emptyempty($this->lastbuilddate)) { 
          $s .= "{$this->lastbuilddate} "; 
       } 
 
       if (!emptyempty($this->generator)) { 
          $s .= "{$this->generator} "; 
       } 
       
       // start items 
       for ($i=0;$iitems),$i++) { 
           $s .= " "; 
           $s .= " "; 
           $s .= "<link />{$this->items[$i][&#39;link&#39;]} "; 
           $s .= "<!--data[{$thi-->items[$i][&#39;description&#39;]}]]> "; 
           $s .= "{$this->items[$i][&#39;pubdate&#39;]} ";           
           $s .= " "; 
       } 
      
      // close channel 
      $s .= " "; 
      $this->content = $s; 
   } 
 
   function show() { 
       if (emptyempty($this->content)) $this->buildrss(); 
       header(&#39;content-type:text/xml&#39;); 
       echo($this->content); 
   } 
 
   function savetofile($fname) { 
       if (emptyempty($this->content)) $this->buildrss(); 
       $handle = fopen($fname, &#39;wb&#39;); 
       if ($handle === false)  return false; 
       fwrite($handle, $this->content); 
       fclose($handle); 
   } 
} 
?>
登录后复制


以上是php 生成RSS文件类实例代码的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!