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

/********************** // * 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; // replace the string array // ----------------------- initialize ------------------------- function __ Construct () {// initialize $ this-> MbUrl = ""; $ this-> OutUrl = ""; $ this-> AllHtml = ""; $ this-> SQL = ""; $ this-> SouChar = ""; $ this-> ObjChar = "";} // --------------------------- automatically replace --------------------------- 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 -------------------} // The replacement string is automatically completed by field ------------------------ // replace the array functions Replacehtml ($ Shuzusou, $ Shuzuobj) {// replace arrays in batches if (count ($ Shuzusou )! = Count ($ Shuzuobj) {exit ("The replacement array does not match");} if ($ this-> AllHtml = "") {exit ("no content to replace") ;}for ($ I = 0; $ I
 
  
AllHtml = str_replace ($ Shuzusou [$ I], $ Shuzuobj [$ I], $ this-> AllHtml); // print ("
  
". $ Shuzusou (I)." = ". $ Shuzuobj (I )."
") }}// Complete batch replacement of arrays -------------------------- // ----------------------------- read the file using function Readfile () {$ file = fopen ($ this-> MbUrl," r "); $ fsize = filesize ($ this-> MbUrl); $ this-> AllHtml = fread ($ file, $ fsize); fclose ($ file );} // The volume reads the file ------------------------------ // ----------------------------- save the function SaveFile () {$ file = fopen ($ this-> OutUrl, "w"); fwrite ($ file, $ this-> AllHtml); fclose ($ file);} // ------------------------------- save the file. ---------------------------- // ---------------------------- generate a static category -------------------------------

Related instances:

// ------------------ Static generation ---- $ MyMake = new Makehtml; $ MyMake-> MbUrl = "News_Show.shtml"; $ MyMake-> Readfile (); $ THTml = $ MyMake-> AllHtml; $ shuzu1 = array (); $ shuzu2 = array (); $ shuzu1 [0] = "<=\ $ keybord \ $> "; $ shuzu1 [1] = "<=\$ description \ $>"; $ shuzu1 [2] = "<=\$ title \ $> "; $ shuzu1 [3] = "<=\$ Title1 \ $>"; $ shuzu1 [4] = "<\$ = Bid \ $> "; $ shuzu1 [5] = "<$ = Id \ $>"; $ shuzu1 [6] = "<=\$ Contentb \ $> "; $ shuzu1 [7] = "<\$ = BigId \ $>"; $ shuzu1 [8] = "<=\$ Date \ $> "; $ shuzu1 [9] = "<=\$ City \ $>"; $ shuzu1 [10] = "<=\$ SmallId \ $> "; $ shuzu1 [11] = "<=\$ CityId \ $>"; $ shuzu1 [12] = "width = \" 100% \""; $ MyMake-> OutUrl = "News_show_1.shtml"; $ shuzu2 [0] = "array 0"; $ shuzu2 [1] = "array 1 "; $ shuzu2 [2] = "array 2"; $ shuzu2 [3] = "array 3"; $ shuzu2 [4] = "array 4 "; $ shuzu2 [5] = "array 5"; $ shuzu2 [6] = "array 6"; $ shuzu2 [7] = "array 7 "; $ shuzu2 [8] = "array 8"; $ shuzu2 [9] = "array 9"; $ shuzu2 [10] = "array 10 "; $ shuzu2 [11] = "array 11"; $ shuzu2 [12] = "width = \" 95% \ ""; $ MyMake-> Replacehtml ($ shuzu1, $ shuzu2 ); $ MyMake-> SaveFile (); // ------------------ static generation completed -----------

The above is a convenient and practical PHP script for generating static page classes (non-smarty) _ php skills. For more information, see PHP Chinese website (www.php1.cn )!

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.