php生成shtml类用法实例_php技巧
May 16, 2016 pm 08:28 PM
php
generate
usage
kind
本文实例讲述了php生成shtml类及其用法。分享给大家供大家参考。具体如下:
复制代码 代码如下:
class Shtml{
var $DataSource; //array 数组
var $Templet; //string 字符串
var $FileName;
//绑定数据源
function BindData($arr){
$this->DataSource = $arr;
}
function Create(){
//只谈思路:
$tmp = $this->Templet;
foreach($this->DataSource as $key=>$value){
//替换模板字符串中 的字符串
$tmp = str_replace('',$value,$tmp);
}
//生成文件,存盘。
$fp = fopen($this->FileName,'w');
if (fwrite ($fp,$tmp)){
fclose ($fp);
}else {
fclose ($fp);
}
}
}
//用法如下:
$arr = array();
$arr["title"] = "这里是标题";
$arr["content"] = "这里是内容";
$obj = new Shtml;
$obj->FileName="xxx.htm";
$obj->Templet="标题:内容:";
$obj->BindData($arr);
//一切OK,万事达吉
$obj->Create();
?>
var $DataSource; //array 数组
var $Templet; //string 字符串
var $FileName;
//绑定数据源
function BindData($arr){
$this->DataSource = $arr;
}
function Create(){
//只谈思路:
$tmp = $this->Templet;
foreach($this->DataSource as $key=>$value){
//替换模板字符串中
$tmp = str_replace('
}
//生成文件,存盘。
$fp = fopen($this->FileName,'w');
if (fwrite ($fp,$tmp)){
fclose ($fp);
}else {
fclose ($fp);
}
}
}
//用法如下:
$arr = array();
$arr["title"] = "这里是标题";
$arr["content"] = "这里是内容";
$obj = new Shtml;
$obj->FileName="xxx.htm";
$obj->Templet="标题:
$obj->BindData($arr);
//一切OK,万事达吉
$obj->Create();
?>
希望本文所述对大家的PHP程序设计有所帮助。
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

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
