Convenient and practical PHP static page generation class (non-smarty)

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.