Home > Backend Development > PHP Tutorial > Convenient and practical PHP to generate static page classes (non-smarty) Page 1/2_PHP Tutorial

Convenient and practical PHP to generate static page classes (non-smarty) Page 1/2_PHP Tutorial

WBOY
Release: 2016-07-21 15:49:17
Original
927 people have browsed it

Copy code The code is as follows:

/*********************/
/* */
/* Version : 5.2.5 */
/* Author : liqiangwork#sohu.com */
/* QQ : 570937581 */
/* */
/*********************/
//--------------------------------Generate static classes------------- ------------------
class Makehtml{
public $MbUrl,$OutUrl,$AllHtml,$SouChar,$ObjChar; //Variables
public $ row; //Cursor
public $Shuzusou,$Shuzuobj; //Replaced string array
//---------------------- Initialization-------------------------
function __construct(){ //Initialization
$this->MbUrl="";
$this->OutUrl="";
$this->AllHtml="";
$this->Sql="";
$this->SouChar=" ";
$this->ObjChar="";
}
//-------------------------- ---Automatically replace by field---------------------------
function AutoReplace(){
//--- ---------------Automatically obtain the string to be replaced------------------
$tlen=count($ row);
$shuzu1=array();
$shuzu2=array();
if($row){
$i=0;
foreach($row as $key => $value){
$shuzu2[i]="<=$".$key."$>";
$shuzu1[i]=$value;
$i++;
}
$this->Replacehtml(shuzu2,shuzu1);
}
//------------------Automatically obtain the replacement String of -------------------
}
//------------------- ----------Automatically replace by field---------------------
//------ -----------------------Batch replace arrays--------------------- --
function Replacehtml($Shuzusou,$Shuzuobj){ //Batch replacement array
if(count($Shuzusou)!=count($Shuzuobj)){
exit("Replacement array does not match" );
}
if($this->AllHtml==""){
exit("No content to replace");
}
for($i=0 ;$i$this->AllHtml=str_replace($Shuzusou[$i],$Shuzuobj[$i],$this->AllHtml);
//print("
".$Shuzusou(i)."=".$Shuzuobj(i)."
")
}
}
//-- -------------------------------Batch replacement of arrays completed------------------ -------
//--------------------------------Read file------ -----------------------------
function Readfile(){
$file=fopen($this->MbUrl, "r");
$fsize=filesize($this->MbUrl);
$this->AllHtml=fread($file,$fsize);
fclose($file);
}
//--------------------------------Reading file completed--------- ---------------------
//------------------------ -----Save file---------------------------------
function SaveFile(){
$file=fopen($this->OutUrl,"w");
fwrite($file,$this->AllHtml);
fclose($file);
}
//--------------------------------Save file completed---------------- -------------
}
//-------------------------- ---Complete generating static classes-------------------------------

Related examples :

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319586.htmlTechArticleCopy the code as follows: /*********************/ /* */ /* Version: 5.2.5 */ /* Author : liqiangwork#sohu.com */ /* QQ : 570937581 */ /* */ /*********************/ //------------...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template