PHP Static Class

Source: Internet
Author: User
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?>
  • Related Article

    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.