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

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("{@", "<?php echo ", $tpl_content);

$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

复制代码代码如下:

/p>

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

new_file

{@$songyu@}

{@$zhangyuan@}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值