Generate a class of static HTML files according to the template file
Generally, we use PHP to output an HTML file, always use $ head = "
... head>" such a long string. This class mainly provides a way of easy to output an HTML file with a PHP. Avoid excessive long strings in the program.Class definition file createhtml.class.php As follows: Php // ***** Define the required operating function / / agreement to mark To start // to mark To end function isbegin ($ str) {$ pattern = ""; if (EREG ($ Pattern) , $ STR)) Return True; Return False;} Function isFinish ($ str) {$ pattern = ""; if (EREG ($ Pattern) , $ STR)) Return True; Return False;} Function GetName ($ STR) {$ TMP = EXPLODE ("##", $ STR); RETURN $ TMP [1];} // ******* ********** // ******* Define class class tcreatehtml {var $ htemplate; var $ modistring; // ******** Interface function / / Construct Template Function TCREATEHTML ($ TMPLATE) {$ this-> HTemplate = $ TMPLATE;} // Setting Output File Name Function Sethtml ($ filename) {$ this-> filename = $ filename;} // Set the name of the tag Corresponding replacement string Function EditableBlock ($ this-> modistring [$ name] = $ replace;} // Write HTML file Function Writehtml () {$ fc = file ($ this-> htemplate) $ Fp = fopen ($ THIS-> FileName, "W"); $ k = count ($ fc); $ begin = false; $ tag = ""; for ($ I = 0; i <$ K; $ I ) {IF (Isbegin ($ FC [$ I])) {FPUTS ($ FP, $ FC [$ I]); $ begin = true; $ number = true; $ tag = getName ($ FC [$ I]); Continue;} IF (ISFINISH ($ FC [$ I])) {FPUTS ($ FP, $ FC [$ I]); $ begin = false; $ first = false; $ tag = ""; continued;}}} ($ begin == True) {IF ($ first == true) {$ FC [$ I] = $ this-> MODISTRING [$ TAG]. "