Convenient and practical PHP static page generation class (non-smarty)
Last Update:2018-04-06
Source: Internet
Author: User
I don't like Smarty. I directly wrote a static class, which is convenient, simple, and practical. I hope you can continue to improve it.
The code is as follows:
/*********************/
/**/
/* Version: 5.2.5 */
/* Author: liqiangwork # sohu.com */
/* QQ: 570937581 */
/**/
/*********************/
// ----------------------------- Generate a static class -------------------------------
Class Makehtml {
Public $ MbUrl, $ OutUrl, $ AllHtml, $ SouChar, $ ObjChar; // variable
Public $ row; // cursor
Public $ Shuzusou, $ Shuzuobj; // string array to be replaced
// ----------------------- Initialize -------------------------
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 string to be replaced -------------------
}
// ------------------------------- Automatically complete field replacement ------------------------
// ------------------------------- Replace arrays in batches --------------------------
Function Replacehtml ($ Shuzusou, $ Shuzuobj) {// replace arrays in batches
If (count ($ Shuzusou )! = Count ($ Shuzuobj )){
Exit ("replacement array does not match ");
}
If ($ this-> AllHtml = ""){
Exit ("no content to be replaced ");
}
For ($ I = 0; $ I $ This-> AllHtml = str_replace ($ Shuzusou [$ I], $ Shuzuobj [$ I], $ this-> AllHtml );
// Print ("
". $ Shuzusou (I)." = ". $ Shuzuobj (I )."
")
}
}
// ------------------------------- Replace arrays in batches --------------------------
// ----------------------------- Read the file ---------------------------------
Function Readfile (){
$ File = fopen ($ this-> MbUrl, "r ");
$ Fsize = filesize ($ this-> MbUrl );
$ This-> AllHtml = fread ($ file, $ fsize );
Fclose ($ file );
}
// ------------------------------- File reading is completed ------------------------------
// ----------------------------- Save the file ---------------------------------
Function SaveFile (){
$ File = fopen ($ this-> OutUrl, "w ");
Fwrite ($ file, $ this-> AllHtml );
Fclose ($ file );
}
// ------------------------------- Save the file ------------------------------
}
// ------------------------------ Complete generating static classes -------------------------------
Related instances: