PHP生成RSS文件類實例_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:php實現(xiàn)兩表合并成新表并且有序排列的方法具體實現(xiàn)方法如下: 代碼如下:?php /** la (3,5,8,11) lb(2,6,8,9,11,15) 合并為lc,有序排列。 用php實現(xiàn),不能用sort之類的函數(shù)!�。�! **/ 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所在地的方法具體實現(xiàn)方法如下: 代碼如下:?php /** *@ date 2010.12.21 注:文件頭 [第一條索引的偏移量 (4byte)] + [最后一條索引的偏移地址 (4byte)] 8字節(jié) 記錄區(qū) [結(jié)束ip (4byte)] + [地區(qū)1] + [地區(qū)2] 4字節(jié)+不定長 索引區(qū) [開始ip (4byte)] + [指向記錄區(qū)的偏移地址 (3byte)]
相關(guān)PHP教程:
- php實現(xiàn)兩表合并成新表并且有序排列的方法
- php查詢ip所在地的方法
- phpmyadmin安裝教程 phpmyadmin安裝配置
- PHP程序員必須遵循的PHP編程準(zhǔn)則
- php提取網(wǎng)頁正文內(nèi)容的例子
- PHP官方Windows擴展列表
- 修改php.ini中的max_input_vars參數(shù)限制提交的表單數(shù)量
- 快速找出php中可能導(dǎo)致cpu飆升問題的代碼行
- php驗證URL是否合法的函數(shù)
- PHP中排列組合及性能對比
- PHP合并2個數(shù)字鍵數(shù)組的值的程序
- php方法重寫:Declaration of should be compatible with that
- 相關(guān)鏈接:
- 教程說明:
PHP教程-PHP生成RSS文件類實例
。