av手机免费在线观看,国产女人在线视频,国产xxxx免费,捆绑调教一二三区,97影院最新理论片,色之久久综合,国产精品日韩欧美一区二区三区

php語(yǔ)言

如何生成靜態(tài)頁(yè)面的PHP類

時(shí)間:2025-05-27 10:04:34 php語(yǔ)言 我要投稿
  • 相關(guān)推薦

如何生成靜態(tài)頁(yè)面的PHP類

  PHP具有非常強(qiáng)大的功能,所有的CGI的功能PHP都能實(shí)現(xiàn),而且支持幾乎所有流行的數(shù)據(jù)庫(kù)以及操作系統(tǒng)。最重要的是PHP可以用C、C++進(jìn)行程序的擴(kuò)展!以下是小編為大家搜索整理的如何生成靜態(tài)頁(yè)面的PHP類,希望能給大家?guī)?lái)幫助!更多經(jīng)常內(nèi)容請(qǐng)及時(shí)關(guān)注我們應(yīng)屆畢業(yè)生考試網(wǎng)!

  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文件信息的來(lái)源網(wǎng)頁(yè)地址

  var $time; //html文件信息填加時(shí)的時(shí)間

  var $dirtype; //目錄存放方式:year,month,,,,

  var $nametype; //html文件命名方式:name

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

  {

  $this->setvar($nametype,$dirtype,$rootdir);

  }

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

  {

  $this->rootdir=$rootdir;

  $this->dirtype=$dirtype;

  $this->nametype=$nametype;

  }

  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))

  {

  @mkdir($cur_dir,0777);

  }

  }

  }

  }

  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];

  }

  function geturlquery($url='')

  {

  $this->url=$url?$url:$this->url;

  $durl=parse_url($this->url);

  $durl=explode("&",$durl[query]);

  foreach($durl as $surl)

  {

  $gurl=explode("=",$surl);

  $eurl[]=$gurl[1];

  }

  return join("_",$eurl);

  }

  function getname($url='',$time=0,$dirname='')

  {

  $this->url=$url?$url:$this->url;

  $this->dirname=$dirname?$dirname:$this->dirname;

  $this->time=$time?$time:$this->time;

  $this->getdir();

  switch($this->nametype)

  {

  case 'name':

  $filename=$this->geturlname().'.htm';

  $this->name=$this->dir.'/'.$filename;

  break;

  case 'time':

  $this->name=$this->dir.'/'.$this->time.'.htm';

  break;

  case 'query':

  $this->name=$this->dir.'/'.$this->geturlquery().'.htm';

  break;

  case 'namequery':

  $this->name=$this->dir.'/'.$this->geturlname().'-'.$this->geturlquery().'.htm';

  break;

  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;

  //上面保證不重復(fù)地把變量賦予該類成員

  if(empty($htmlname))

  $this->getname();

  else

  $this->name=$dirname.'/'.$htmlname; //得到name

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

  ///////////////關(guān)鍵步---用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)))

  {

  if($filename!="."&&$filename!="..")

  $this->deletedir($file."/".$filename);

  }

  closedir($handle);

  rmdir($file);

  return true;

  }else{

  unlink($file);

  }

  }

  }

  }

  ?>

【如何生成靜態(tài)頁(yè)面的PHP類】相關(guān)文章:

php靜態(tài)頁(yè)生成方法10-25

php技術(shù)生成靜態(tài)頁(yè)面的方法07-28

php生成靜態(tài)頁(yè)面的詳細(xì)教程10-15

如何實(shí)現(xiàn)PHP靜態(tài)新聞列表自動(dòng)生成代碼08-19

生成PHP網(wǎng)站頁(yè)面靜態(tài)化的方法06-14

PHP中使用smarty生成靜態(tài)文件的實(shí)例10-25

PHP生成靜態(tài)HTML頁(yè)面最簡(jiǎn)單方法示例10-13

php如何生成隨機(jī)密碼07-01

如何給php生成隨機(jī)密碼09-09