PHP生成RSS文件类实例


Posted in PHP onDecember 05, 2014

本文实例讲述了PHP生成RSS文件类文件。分享给大家供大家参考。具体如下:

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

<?php 

if (defined('_class_rss_php')) return; 

define('_class_rss_php教程',1); 

/** 

 

 *  使用说明: 

 *  $rss = new rss('redfox','http://3water.com/',"redfox's blog"); 

 *  $rss->additem('rss class',"https://3water.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程序设计有所帮助。

PHP 相关文章推荐
用php解析html的实现代码
Aug 08 PHP
解析PHP无限级分类方法及代码
Jun 21 PHP
浅析php中json_encode()和json_decode()
May 25 PHP
phpmyadmin出现Cannot start session without errors问题解决方法
Aug 14 PHP
PHP间隔一段时间执行代码的方法
Dec 02 PHP
Mac系统下使用brew搭建PHP(LNMP/LAMP)开发环境
Mar 03 PHP
PHP数据库表操作的封装类及用法实例详解
Jul 12 PHP
PHP链表操作简单示例
Oct 15 PHP
php 调用ffmpeg获取视频信息的简单实现
Apr 03 PHP
PHP实现webshell扫描文件木马的方法
Jul 31 PHP
ThinkPHP实现的rsa非对称加密类示例
May 29 PHP
基于laravel Request的所有方法详解
Sep 29 PHP
php实现两表合并成新表并且有序排列的方法
Dec 05 #PHP
ThinkPHP中redirect用法分析
Dec 05 #PHP
php查询ip所在地的方法
Dec 05 #PHP
smarty实现多级分类的方法
Dec 05 #PHP
Codeigniter框架实现获取分页数据和总条数的方法
Dec 05 #PHP
常见php数据文件缓存类汇总
Dec 05 #PHP
Thinkphp搜索时首页分页和搜索页保持条件分页的方法
Dec 05 #PHP
You might like
php正则preg_replace_callback函数用法实例
2015/06/01 PHP
使用Thinkphp框架开发移动端接口
2015/08/05 PHP
PHP实现webshell扫描文件木马的方法
2017/07/31 PHP
JS遮罩层效果 兼容ie firefox jQuery遮罩层
2010/07/26 Javascript
jquery 绑定回车动作扑捉回车键触发的事件
2014/03/26 Javascript
JS字符串拼接在ie中都报错的解决方法
2014/03/27 Javascript
javascript入门之数组[新手必看]
2016/11/21 Javascript
纯js实现悬浮按钮组件
2016/12/17 Javascript
JS实现拖拽的方法分析
2016/12/20 Javascript
JS设置时间无效问题的解决办法
2017/02/18 Javascript
微信小程序页面滑动屏幕加载数据效果
2020/11/16 Javascript
深入理解Vue.js源码之事件机制
2017/09/27 Javascript
jQuery中图片展示插件highslide.js的简单dom
2018/04/22 jQuery
微信小程序实现基于三元运算验证手机号/姓名功能示例
2019/01/19 Javascript
原生JS实现图片懒加载之页面性能优化
2019/04/26 Javascript
Vue CLI4 Vue.config.js标准配置(最全注释)
2020/06/05 Javascript
[39:07]LGD vs VP 2018国际邀请赛淘汰赛BO3 第二场 8.21
2018/08/22 DOTA
[39:53]完美世界DOTA2联赛PWL S2 LBZS vs Forest 第一场 11.19
2020/11/19 DOTA
Python Nose框架编写测试用例方法
2017/10/26 Python
python 接口测试response返回数据对比的方法
2018/02/11 Python
Go/Python/Erlang编程语言对比分析及示例代码
2018/04/23 Python
Linux下python与C++使用dlib实现人脸检测
2018/06/29 Python
Python使用pyautogui模块实现自动化鼠标和键盘操作示例
2018/09/04 Python
python 列表中[ ]中冒号‘:’的作用
2019/04/30 Python
python 模拟创建seafile 目录操作示例
2019/09/26 Python
python有几个版本
2020/06/17 Python
使用phonegap检测网络状态的方法
2017/03/30 HTML / CSS
SKECHERS斯凯奇中国官网:来自美国的运动休闲品牌
2018/11/14 全球购物
Unix控制后台进程都有哪些进程
2016/09/22 面试题
最新英语专业学生求职信范文
2013/09/21 职场文书
高校毕业生自我鉴定
2013/10/27 职场文书
医院2014国庆节活动策划方案
2014/09/21 职场文书
2015年十一国庆节演讲稿
2015/03/20 职场文书
2015年化工厂工作总结
2015/05/04 职场文书
python Polars库的使用简介
2021/04/21 Python
详细分析PHP7与PHP5区别
2021/06/26 PHP