php专区

 首页 > php专区 > PHP应用 > php类库 > PHP RSS 生成类 - php类库

PHP RSS 生成类 - php类库

分享到:
【字体:
导读:
          同时也可以用网页来解析xml文档,PHP RSS 生成类实例代码如下:?phpif(defined(#39;_class_rss_php#39;))return;define(#39;_class_rss......

PHP RSS 生成类

同时也可以用网页来解析xml文档,PHP RSS 生成类实例代码如下:

  1. if (defined('_class_rss_php')) return
  2. define('_class_rss_php教程',1); 
  3. /** 
  4.  
  5.  *  使用说明: 
  6.  *  $rss = new rss('redfox','http://phpfensi.com/',"redfox's blog"); 
  7.  *  $rss->additem('rss class',"http://www.phpfensi.com","xxx",date()); 
  8.  *  $rss->additem(...); 
  9.  *  $rss->savetofile(...); 
  10.  */ 
  11.  
  12. class rss { 
  13.    //public 
  14.    $rss_ver = "2.0"
  15.    $channel_title = ''
  16.    $channel_link = ''
  17.    $channel_description = ''
  18.    $language = 'zh_cn'
  19.    $copyright = ''
  20.    $webmaster = ''
  21.    $pubdate = ''
  22.    $lastbuilddate = ''
  23.    $generator = 'redfox rss generator'
  24.  
  25.  
  26.    $content = ''
  27.    $items = array(); 
  28.  
  29.  
  30.    function rss($title$link$description) { 
  31.        $this->channel_title = $title
  32.        $this->channel_link = $link
  33.        $this->channel_description = $description
  34.        $this->pubdate = date('y-m-d h:i:s',time()); 
  35.        $this->lastbuilddate = date('y-m-d h:i:s',time()); 
  36.    } 
  37.  
  38.  
  39.    function additem($title$link$description ,$pubdate) { 
  40.        $this->items[] = array('titile' => $title , 
  41.                         'link' => $link
  42.                         'description' => $description
  43.                         'pubdate' => $pubdate); 
  44.    } 
  45.  
  46.  
  47.    function buildrss() { 
  48.        $s = " "
  49.        // start channel 
  50.        $s .= " "
  51.        $s .= " " 
  52.        $s .= "{$this->channel_link} "
  53.        $s .= "{$this->channel_description} "
  54.        $s .= "{$this->language} "
  55.        if (!emptyempty($this->copyright)) { 
  56.           $s .= "{$this->copyright} "
  57.        } 
  58.        if (!emptyempty($this->webmaster)) { 
  59.           $s .= "{$this->webmaster} "
  60.        } 
  61.        if (!emptyempty($this->pubdate)) { 
  62.           $s .= "{$this->pubdate} "
  63.        } 
  64.  
  65.  
  66.        if (!emptyempty($this->lastbuilddate)) { 
  67.           $s .= "{$this->lastbuilddate} "
  68.        } 
  69.  
  70.  
  71.        if (!emptyempty($this->generator)) { 
  72.           $s .= "{$this->generator} "
  73.        } 
  74.        
  75.        // start items 
  76.        for ($i=0;$iitems),$i++) { 
  77.            $s .= " "
  78.            $s .= " "
  79.            $s .= "{$this->items[$i]['link']} "
  80.            $s .= "items[$i]['description']}]]> "
  81.            $s .= "{$this->items[$i]['pubdate']} ";           
  82.            $s .= " "
  83.        } 
  84.       
  85.       // close channel 
  86.       $s .= " "
  87.       $this->content = $s
  88.    } 
  89.  
  90.  
  91.    function show() { 
  92.        if (emptyempty($this->content)) $this->buildrss(); 
  93.        header('content-type:text/xml'); 
  94.        echo($this->content); 
  95.    } 
  96. //开源代码phpfensi.com 
  97.  
  98.    function savetofile($fname) { 
  99.        if (emptyempty($this->content)) $this->buildrss(); 
  100.        $handle = fopen($fname'wb'); 
  101.        if ($handle === false)  return false; 
  102.        fwrite($handle$this->content); 
  103.        fclose($handle); 
  104.    } 
  105.  
  106. ?> 
分享到:
php读取xml文件的xml实例代码 - php类库
php读取xml文件的xml实例代码 本文章为你提供一款php xml读取类,很简单的一个xml分析类了,它可读取指它xml文档,并且输出或取得指定节点的xml数据,代码如下:  
php 完美的rss 生成类 - php类库
php 完美的rss 生成类
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……