First, Static class
Copy the following code, save as file static.class.php
1
Templet = ""; $this->datasource = Array (); $this->filename = ""; $this->mod = "WB"; $this->handle = false; 22}23//bound data source, parameter is an array of function binddata ($arr), {$this->datasource = $arr; 27}28/ /set path and file name Setfilename ($fileName) {$this->filename = $fileName;}33 Fun Ction Open () ($this->handle = fopen ($this->filename, $this->mod)), and return $this ->handle;37 else38 return false;39}40 function Close (), fclose ($th Is->handle)}44 function Write ($content) {fwrite return ($this->handle, $content); 47 }48//Create a directory that supports absolute and relative paths relative to the current script. Linux under the notice to have permission to the MkDir ($pathname) {$pathname) {str_replace ("\ \", "/", $pathna Me) if (!file_exists ($pathnAME) {0777 (! @mkdir ($pathname)) {echo "Failed to create folder"; exit;57 }58}59}else{60 return false;61}62}63//Generate static file up to F Unction Create () $tmp = $this->templet;67 foreach ($this->datasource as $key + $value) {$tmp = Str_replace ($key, $value, $tmp);}70 $this->mkdir (dirname ($this->filenam e); $this->open (), $this->write ($tmp), $this->close ();}75}76?>
Ii. Methods of Use
Copy the following code and save it as a PHP file, such as test.php
1
"A", "3" and "C");//Tag substitution rules createshtml ($buffer, $filename, $filepath, $arr);}14 function Createshtml ($buffer, $filename, $filepath, $arr =array ()) { $shtml = new shtml (); $shtml->setfilename ($ filepath. $filename); $shtml->templet = $buffer, $shtml->binddata ($arr), $shtml Create ();}21?>