PHP生成RSS文件类实例_PHP教程
教程Tag:暂无Tag,欢迎添加,赚取U币!
推荐:php实现两表合并成新表并且有序排列的方法具体实现方法如下: 代码如下:?php /** la (3,5,8,11) lb(2,6,8,9,11,15) 合并为lc,有序排列。 用php实现,不能用sort之类的函数!!!! **/ class union { var $lista = array(); var $listb = array(); var $listc = array(); function getlenght($arr
代码如下: <?phpif (defined('_class_rss_php')) return;
define('_class_rss_php教程',1);
/**
* 使用说明:
* $rss = new rss('redfox','http://jb51.net/',"redfox's blog");
* $rss->additem('rss class',"http://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查询ip所在地的方法具体实现方法如下: 代码如下:?php /** *@ date 2010.12.21 注:文件头 [第一条索引的偏移量 (4byte)] + [最后一条索引的偏移地址 (4byte)] 8字节 记录区 [结束ip (4byte)] + [地区1] + [地区2] 4字节+不定长 索引区 [开始ip (4byte)] + [指向记录区的偏移地址 (3byte)]
相关PHP教程:
- 相关链接:
- 教程说明:
PHP教程-PHP生成RSS文件类实例。