PHP RSS 生成类
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-20 15:28:20 浏览: 评论:0
同时也可以用网页来解析xml文档,PHP RSS 生成类实例代码如下:
- <?php
- if (defined('_class_rss_php')) return;
- define('_class_rss_php教程',1);
- /**
- * 使用说明:
- * $rss = new rss('redfox','http://phpfensi.com/',"redfox's blog");
- * $rss->additem('rss class',"http://www.phpfensi.com","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 (!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]['link']} ";
- $s .= "<!--data[{$thi-->items[$i]['description']}]]> ";
- $s .= "{$this->items[$i]['pubdate']} ";
- $s .= " ";
- }
- // close channel
- $s .= " ";
- $this->content = $s;
- }
- function show() {
- if (emptyempty($this->content)) $this->buildrss();
- header('content-type:text/xml');
- echo($this->content);
- }
- //开源代码phpfensi.com
- function savetofile($fname) {
- if (emptyempty($this->content)) $this->buildrss();
- $handle = fopen($fname, 'wb');
- if ($handle === false) return false;
- fwrite($handle, $this->content);
- fclose($handle);
- }
- }
- ?>
Tags: PHP RSS 生成类
- 上一篇:php读取xml文件的xml实例代码
- 下一篇:php 完美的rss 生成类
相关文章
- ·PHP多功能图片处理类(2013-11-11)
- ·PHP 生成缩略图的类(2013-11-13)
- ·一个分页显示类(2013-11-13)
- ·分享的一个分页类(2013-11-13)
- ·简单的php分页类(2013-11-14)
- ·一个功能比较高的分页类(for PHP5.x)(2013-11-28)
- ·phpword中文字符乱码解决办法(2013-12-05)
- ·一个比较完善的购物车类(2013-12-08)
- ·php面象对象数据库操作类(2013-12-09)
- ·PHP顶层类(2013-12-10)
- ·PHP静态文件生成类(2013-12-10)
- ·PHP分页类(2013-12-10)
- ·非常简单的日历类(2013-12-11)
- ·php数字分页类的代码(2013-12-23)
- ·PHP货币换算程序代码(2013-12-27)
- ·实现多文件上传php类(2014-01-03)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)