php 生成html靜態檔類程式與實例使用方法

來源:互聯網
上載者:User
關鍵字 網路程式設計 PHP教程

php教程生成html靜態檔類程式與實例使用方法
class html
{
var $dir; dir for the htmls(without/)
var $rootdir; root of html files(without/):html
var $name; html檔存放路徑
var $dirname; 指定的資料夾名稱
var $url; 獲取html檔資訊的來源網頁位址
var $time; html檔資訊填加時的時間
var $dirtype; 目錄存放方式:year,month,,,,
var $nametype; html檔命名方式:name

function html($nametype='name',$dirtype='year',$rootdir='html')


function setvar($nametype='name',$dirtype='year',$rootdir='html')


function createdir($dir='')
{
$this->dir=$dir?$dir:$this->dir;

if (!is_dir($this->dir))
{
$temp = explode('/',$this->dir);
$cur_dir = '';
for($i=0;$i {
$cur_dir .= $temp[$i].' /';
if (!is_dir($cur_dir))

}
}
}

function getdir($dirname='',$time=0)
{
$this->time=$time?$time:$this->time;
$this->dirname=$dirname?$dirname:$this->dirname;

switch($this->dirtype)
{
case 'name':
if(empty($this->dirname))
$this->dir=$this->rootdir;
else
$this->dir=$this->rootdir.' /'.$this->dirname;
break;
case 'year':
$this->dir=$this->rootdir.' /'.date("Y",$this->time);
break;

case 'month':
$this->dir=$this->rootdir.' /'.date("Y-m",$this->time);
break;

case 'day':
$this->dir=$this->rootdir.' /'.date("Y-m-d",$this->time);
break;
}

$this->createdir();

return $this->dir;
}

function geturlname($url='')
{
$this->url=$url?$url:$this->url;

$filename=basename($this->url);
$filename=explode(".",$filename);
return $filename[0];
}

case 'nametime':
$this->name=$this->dir.'/'.$this->geturlname().' -'.$this->time.'. htm';
break;

}
return $this->name;
}

function createhtml($url='',$time=0,$dirname='',$htmlname='')
{
$this->url=$url?$url:$this->url;
$this->dirname=$dirname?$dirname:$this->dirname;
$this->time=$time?$time:$this->time;
上面保證不重複地把變數賦予該類成員
if(empty($htmlname))
$this->getname();
else
$this->name=$dirname.' /'.$htmlname; 得到name

$content=file($this->url) or die("Failed to open the url ".$this->url." !");;

關鍵步---用file讀取$this->url


$content=join("",$content);
$fp=@fopen($this->name,"w") or die("Failed to open the file ".$this->name." !");
if(@fwrite($fp,$content))
return true;
else
return false;
fclose($fp);
}
以name為名字生成html

function deletehtml($url='',$time=0,$dirname='')
{
$this->url=$url?$url:$this->url;
$this->time=$time?$time:$this->time;

$this->getname();

if(@unlink($this->name))
return true;
else
return false;
}

/**
* function::deletedir()
* 刪除目錄
* @param $file 目錄名(不帶/)
* @return
*/
function deletedir($file)
{
if(file_exists($file))
{
if(is_dir($file))
{
$handle =opendir($file);
while(false!==($filename=readdir($handle)))

closedir($handle);
rmdir($file);
return true;
}else
}
}

}
?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.