Pain全世界最小最简单的PHP模板引擎(普通版)_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Pain全世界最小最简单的PHP模板引擎(普通版)_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1414字,纯文字阅读大概需要3分钟。
内容图文
![Pain全世界最小最简单的PHP模板引擎(普通版)_PHP教程](/upload/InfoBanner/zyjiaocheng/170/82bf67f642424fc59f06d484f445b58d.jpg)
Pain.php
代码如下:
class Pain
{
public $var=array();
public $tpl=array();
//this is the method to assign vars to the template
public function assign($variable,$value=null)
{
$this->var[$variable]=$value;
}
public function display($template_name,$return_string=false)
{
//first find whether the tmp file in tmp dir exists.
if(file_exists("tmp/temp_file.php"))
{
unlink("tmp/temp_file.php");
}
extract($this->var);
$tpl_content=file_get_contents($template_name);
$tpl_content=str_replace("{@", "$tpl_content=str_replace("@}", " ?>", $tpl_content);
//create a file in the /tmp dir and put the $tpl_contentn into it, then
//use 'include' method to load it!
$tmp_file_name="temp_file.php";
//$tmp is the handler
$tmp=fopen("tmp/".$tmp_file_name, "w");
fwrite($tmp, $tpl_content);
include "tmp/".$tmp_file_name;
}
}
?>
test.php
代码如下:
require_once "Pain.php";
$pain=new Pain();
$songyu="songyu nb";
$zhangyuan="zhangyuan sb";
$pain->assign("songyu",$songyu);
$pain->assign("zhangyuan",$zhangyuan);
$pain->display("new_file.html");
?>
new_file.html
代码如下:
"http://www.w3.org/TR/html4/strict.dtd">
new_file
{@$songyu@}
{@$zhangyuan@}
http://www.bkjia.com/PHPjc/324330.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324330.htmlTechArticle打包下载 Pain.php 代码如下:
?php class Pain { public $var=array(); public $tpl=array(); //this is the method to assign vars to the template public function assi...
内容总结
以上是互联网集市为您收集整理的Pain全世界最小最简单的PHP模板引擎(普通版)_PHP教程全部内容,希望文章能够帮你解决Pain全世界最小最简单的PHP模板引擎(普通版)_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。