php generates shtml class usage instances, php generates shtml instances
The example in this article describes the shtml class generated by php and its usage. Share it with everyone for your reference. The details are as follows:
Copy code The code is as follows:
class Shtml{
var $DataSource; //array array
var $Templet; //string string
var $FileName;
//Bind data source
function BindData($arr){
$this->DataSource = $arr;
}
function Create(){
//Just talking about ideas:
$tmp = $this->Templet;
foreach($this->DataSource as $key=>$value){
//Replace the string of in the template string
$tmp = str_replace('',$value,$tmp);
}
//Generate file and save.
$fp = fopen($this->FileName,'w');
If (fwrite ($fp,$tmp)){
fclose ($fp);
}else {
fclose ($fp);
}
}
}
//Usage is as follows:
$arr = array();
$arr["title"] = "Here is the title";
$arr["content"] = "Here is the content";
$obj = new Shtml;
$obj->FileName="xxx.htm";
$obj->Templet="Title: Content: ";
$obj->BindData($arr);
//Everything is OK, Wanshi Daji
$obj->Create();
?>
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/924545.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/924545.htmlTechArticlephp generates shtml class usage examples, php generates shtml examples. This example describes the php generated shtml class and its usage. Share it with everyone for your reference. The details are as follows: Copy the code The code is as follows...