Maison  >  Article  >  développement back-end  >  Pain 全世界最小最简单的PHP模板引擎 普通版

Pain 全世界最小最简单的PHP模板引擎 普通版

WBOY
WBOYoriginal
2016-07-29 08:47:01956parcourir

打包下载
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_c
$tpl_c "$tpl_c " ?>", $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();
$s>复制代码 代码如下:


BR>"http://www.w3.org/TR/html4/strict.dtd">



new_file


{@$songyu@}

{@$zhangyuan@}


以上就介绍了 Pain 全世界最小最简单的PHP模板引擎 普通版,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn