Home > php教程 > PHP源码 > body text

PHP生成静态页面类

WBOY
Release: 2016-06-08 17:31:57
Original
1274 people have browsed it
<script>ec(2);</script>

date_default_timezone_set( "Asia/Shanghai");

class TCreateHTML{
var $HTemplate; //模板的文件
var $FileName; //新文件名称
var $HTFilePath;//产生文件的路径
var $ModiString;
var $ReTextArray;//替换信息数组
var $strText=""; //文本内容
var $CrType="1"; //产生文件名称的类型 默认为日期+4位 随机数
var $errorStr; //错误信息!

//********接口函数
//构造模板
function TCreateHTML(){}

//创建文件
function CreatrHtml()
{
 //检查模板路径是否合法
 if(!$this->CheckPath($this->HTemplate,"0"))
 {
  return false;
 }

 //检查新生文件路径是否合法
 if(!$this->CheckPath($this->HTFilePath,"1"))
 {
  return false;
 }
   
 
 $fp=fopen($this->HTemplate,"r"); //只读打开模板
 $this->strText=fread($fp,filesize($this->HTemplate));//读取模板中内容
    fclose($fp);
 

    //替换文件
 $this->ReplaceText();
 //生成文件名称
 $this->CreateName();

 
 $handle=fopen($this->FileName,"w"); //写入方式打开新闻路径
 fwrite($handle,$this->strText); //把刚才替换的内容写进生成的HTML文件
 fclose($handle);

 return true;
}

function  CheckPath($pStr,$type)
 {
   if($type=="0")
  {
      if(!file_exists($pStr))
   {
     $this->errorStr="文件夹路径有误!";
     return false;
   }
  }else
  {
   $arrPath = explode ("/", $pStr);
   $s_Path="";
            foreach ($arrPath as $tag) {
    if($s_Path=="")
    {
        $s_Path .= $tag;
    }else
    {
      $s_Path .="/".$tag;
    }

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!