PHP RSS 生成类
同时也可以用网页来解析xml文档,PHP RSS 生成类实例代码如下:
<?php if (defined( '_class_rss_php' )) return ; define( '_class_rss_php教程' ,1); /** * 使用说明: * $rss = new rss('redfox','http://phpfensi测试数据/',"redfox's blog"); * $rss->additem('rss class',"http://HdhCmsTestphpfensi测试数据","xxx",date()); * $rss->additem(...); * $rss->savetofile(...); */ class rss { //public $rss_ver = "2.0" ; $channel_title = '' ; $channel_link = '' ; $channel_description = '' ; $language = 'zh_cn' ; $copyright = '' ; $webmaster = '' ; $pubdate = '' ; $lastbuilddate = '' ; $generator = 'redfox rss generator' ; $content = '' ; $items = array (); function rss( $title , $link , $description ) { $this ->channel_title = $title ; $this ->channel_link = $link ; $this ->channel_description = $description ; $this ->pubdate = date ( 'y-m-d h:i:s' ,time()); $this ->lastbuilddate = date ( 'y-m-d h:i:s' ,time()); } function additem( $title , $link , $description , $pubdate ) { $this ->items[] = array ( 'titile' => $title , 'link' => $link , 'description' => $description , 'pubdate' => $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 (! empty empty ( $this ->copyright)) { $s .= "{$this->copyright} " ; } if (! empty empty ( $this ->webmaster)) { $s .= "{$this->webmaster} " ; } if (! empty empty ( $this ->pubdate)) { $s .= "{$this->pubdate} " ; } if (! empty empty ( $this ->lastbuilddate)) { $s .= "{$this->lastbuilddate} " ; } if (! empty empty ( $this ->generator)) { $s .= "{$this->generator} " ; } // start items for ( $i =0; $iitems ), $i ++) { $s .= " " ; $s .= " " ; $s .= "<link />{$this->items[$i]['link']} " ; $s .= "<!--data[{$thi-->items[$i]['description']}]]> " ; $s .= "{$this->items[$i]['pubdate']} " ; $s .= " " ; } // close channel $s .= " " ; $this ->content = $s ; } function show() { if ( empty empty ( $this ->content)) $this ->buildrss(); header( 'content-type:text/xml' ); echo ( $this ->content); } //开源代码phpfensi测试数据 function savetofile( $fname ) { if ( empty empty ( $this ->content)) $this ->buildrss(); $handle = fopen ( $fname , 'wb' ); if ( $handle === false) return false; fwrite( $handle , $this ->content); fclose( $handle ); } } ?>查看更多关于PHP RSS 生成类 - php类库的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did29551