时间:2021-05-26
本文实例讲述了PHP生成RSS文件类文件。分享给大家供大家参考。具体如下:
PHP RSS 生成类实例代码如下:
复制代码 代码如下:<?php
if (defined('_class_rss_php')) return;
define('_class_rss_php教程',1);
/**
* 使用说明:
* $rss = new rss('redfox','http://jb51.net/',"redfox's blog");
* $rss->additem('rss class',"https://www.jb51.net","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程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了php生成RSS订阅的方法。分享给大家供大家参考。具体分析如下:RSS(简易信息聚合,也叫聚合内容)是一种描述和同步网站内容的格式。RSS可以是以
本文实例讲述了PHP实现动态创建XML文档的方法。分享给大家供大家参考,具体如下:一.代码conn.phpindex.php查看rss.xml文件中的内容rss
本文实例讲述了php制作基于xml的RSS订阅源功能。分享给大家供大家参考,具体如下:首先制作一个RSS模板,模板的文件名是feed.xml,代码如下:再就是用
本文实例讲述了PHP解析RSS的方法。分享给大家供大家参考。具体如下:1.php代码如下:复制代码代码如下:parse();foreach($rss->getI
本文实例讲述了PHP静态文件生成类。分享给大家供大家参考。具体实现代码如下:复制代码代码如下:mkdir($prefix='article');$fileNam