Home > Backend Development > PHP Tutorial > PHP generates shtml class usage examples, PHP generates shtml examples_PHP tutorial

PHP generates shtml class usage examples, PHP generates shtml examples_PHP tutorial

WBOY
Release: 2016-07-13 10:12:06
Original
721 people have browsed it

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.

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template