PHP静态类
<?php 
class Shtml     
     
{     
     var 
$Templet
     var 
$DataSource
     var 
$Dir
     
     var 
$fileName
     var 
$mod
     var 
$handle
     
     function 
Shtml($fileName="")     
     {     
         
$this->fileName=$fileName
         
$this->mod="wb"
         
$this->handle=false
     
         
$this->Templet     ""
         
$this->DataSource     = array(); 
         
$this->Dir         ""
     }     
         
     
///     <描述> 
     ///     绑定数据源,参数为一数组。 
     ///     </描述> 
     
function BindData($arr)     
     {     
         
$this->DataSource $arr
     }     
         
     
///     <描述> 
     ///     设置文件存放路径。 
     ///     </描述> 
     
function SetDir($dir)     
     {     
         
$this->Dir $dir
     }     
     function 
SetFileName($fileName)     
     {     
         return 
$this->fileName=$fileName
     }     
     
     function 
GetMod()     
     {     
         return 
$this->mod
     }     
     function 
SetMod($mod)     
     {     
         return 
$this->mod=$mod
     }     
     function 
Open()     
     {     
         if(
substr($this->fileName,0,1)=="/")     
             
$this->fileName $_SERVER['DOCUMENT_ROOT'] . $this->fileName
         if(
$this->handle=fopen($this->fileName$this->mod))     
             return 
$this->handle
         else     
             return 
false
     }     
     function 
Close()     
     {     
         return 
fclose($this->handle); 
     }     
     function 
Write($content)     
     {     
         return 
fwrite($this->handle,$content); 
     }     
     function 
MkDir($pathname)     
     {     
         
$currentPath=""
         
str_replace("\","/",$pathname); 
         $pathArr = split("
/",$pathname); 
         if($pathArr[0] == "")     //使用绝对路径 
         { 
             $currentPath = $_SERVER['DOCUMENT_ROOT']; 
         } 
         else 
         { 
             $currentPath = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']); 
         } 
         for($i=0; $i<count($pathArr); $i++) 
         { 
             if($pathArr[$i]=="") 
             continue; 
             else 
             if(is_dir($currentPath . "
/" . $pathArr[$i])) 
                 $currentPath = $currentPath . "
/" . $pathArr[$i]; 
             else 
                 mkdir($currentPath = $currentPath . "
/" . $pathArr[$i]); 
         } 
     } 
     
     ///     <描述> 
     ///     生成静态文件。 
     ///     </描述> 
     function Create() 
     { 
         $tmp = $this->Templet; 
         foreach($this->DataSource as $key=>$value) 
         { 
             $tmp = str_replace("
<FIELD_" . $key . ">", $value, $tmp); 
         } 
         $this->MkDir(dirname($this->fileName)); 
         $this->Open(); 
         $this->Write($tmp); 
         $this->Close(); 
     } 
     } 
     
     function CreateShtml() 
     { 
     ob_start("
callback_CteateShtml"); 
     } 
     function callback_CteateShtml($buffer) 
     { 
     $page = intval(@$_REQUEST["
page"]); 
     $shtml = new Shtml(); 
     $shtml->SetFileName($_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "
/" . basename($_SERVER['PHP_SELF'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm"); 
     $shtml->Templet = $buffer; 
     $shtml->Create(); 
     return $buffer; 
     } 
?>
« 上一篇 | 下一篇 »
只显示10条记录相关文章
php header 跳转 (浏览: 451, 评论: 0)
定时清理旧的log文件 (浏览: 1806, 评论: 1)
FIREFOX取动态input值 (浏览: 1158, 评论: 0)
用css方式巧妙保护邮箱地址 (浏览: 1183, 评论: 0)
PHP5_OOP面向对象---教程下载 (浏览: 2299, 评论: 0)
vc++中用ado连接oracle数据库 (浏览: 4173, 评论: 0)
在DISDUZ!5.5中添加代码高亮插件成功 (浏览: 3123, 评论: 1)
xajax+php的一个DEMO--Blackjack(21点) (浏览: 3503, 评论: 3)
关于使用PHP6的感受 (浏览: 2735, 评论: 0)
[PHP AJAX] 简单比较 xajax、AJASON、flxAJAX、Aja... (浏览: 2711, 评论: 0)
Trackbacks
点击获得Trackback地址,Encode: UTF-8 点击获得Trackback地址,Encode: GB2312 or GBK 点击获得Trackback地址,Encode: BIG5
发表评论

评论内容(*):