Php generate static page html document class-PHP source code

Source: Internet
Author: User
Next let's take a look at the program that uses php to generate html static pages. It's a very simple class. Let's take a look at it without having to talk too much. Next let's take a look at the program that uses php to generate html static pages. It's a very simple class. Let's take a look at it without having to talk too much.

Script ec (2); script

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


$ 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 ();

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.