Use PHP to generate static pages

xiaoxiao2021-03-06  37

Autohtml.php

Var $ filename; var $ mod; var $ handle;

Function SHTML ($ filename = ") {$ this-> filename = $ filename; $ this-> mod =" wb "; $ this-> handle = false;

$ this-> templet = ""; $ this-> datasource = array (); $ this-> dir = "}

/// /// Binding data source, parameter is an array. /// Function BindData ($ arr) {$ this-> DataSource = $ arr;}

/// /// Setting the file storage path. /// Function setDir ($ dir) {$ this-> DIR = $ dir; function setFileName ($ filename) {Return $ this-> filename = $ filename;}

Function getMod () {return $ this-> mod;} function setmod ($ mod) {return $ this-> mod = $ mod;} function open () {if (Substr ($ this-> filename, 0, 1) == "/") $ == "filename = $ _server ['document_root']. $ this-> filename; if ($ this-> handle = fopen ($ this-> filename, $ this-> mod) Return) Return $ this-> Handle; Else Return false;} Function Close () {Return Fclose ($ this-> Handle);} Function Write ($ THIS-> Handle, $ Content);} Function Mkdir ($ cathname) {$ currentpath = ""; str_replace ("//", "/", $ PATHNAME); $ PATHARR = Split ("/", $ Pathname); if ($ PATHARR [0] == " ) // Use absolute path {$ currentpath = $ _server ['Document_Root'];} else {$ currentpath = $ _server ['Document_Root']. DIRNAME ($ _ Server ['php_self']);} for ($ I = 0 $ I /// Generate Static file. /// Function Create ($ TMP = $ THIS-> Templet; Foreach ($ THIS-> DataSource AS $ Key => $ value) {$ TMP = STR_REPLACE ("", $ value, $ TMP);} $ this-> mkdir (Dirname); $ this-> open (); $ this-> Write ($ TMP); $ this-> CLOSE ();}}

function CreateShtml () {ob_start ( "callback_CteateShtml");} function callback_CteateShtml ($ buffer) {$ page = intval (@ $ _ REQUEST [ "page"]); $ shtml = new Shtml (); $ shtml-> SetFileName ($ _Server ['Document_Root']. DirName ($ _ Server ['PHP_SELF'). "/". BaseName ($ _ server ['php_self'], ". PHP"). ($ PAGE == 0? ":" _ "Strval ($ page));" .htm "); $ html-> templet = $ buffer; $ shtml-> create (); return $ buffer;}?>

转载请注明原文地址:https://www.9cbs.com/read-71723.html

New Post(0)