PHP生成RSS文件类实例
发布:smiling 来源: PHP粉丝网 添加日期:2021-05-02 21:32:43 浏览: 评论:0
这篇文章主要介绍了PHP生成RSS文件类,可实现PHP生成RSS文件的功能,对于网站建设与优化来说具有一定的实用价值,需要的朋友可以参考下
本文实例讲述了PHP生成RSS文件类文件。分享给大家供大家参考。具体如下:
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',"https://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);
- }
- function savetofile($fname) {
- if (emptyempty($this->content)) $this->buildrss();
- $handle = fopen($fname, 'wb');
- if ($handle === false) return false;
- fwrite($handle, $this->content);
- fclose($handle);
- }
- }
- ?>
希望本文所述对大家的PHP程序设计有所帮助。
Tags: PHP生成类 RSS文件类
- 上一篇:常见php数据文件缓存类汇总
- 下一篇:简单实用的PHP防注入类实例
相关文章
- ·php静态文件生成类(2014-09-09)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)