国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

Pain 全世界最小最簡單的PHP模板引擎 (普通版)

2024-05-04 23:16:54
字體:
來源:轉載
供稿:網友
打包下載

Pain.php

復制代碼 代碼如下:


<?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

復制代碼 代碼如下:


<?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

復制代碼 代碼如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>new_file</title>
</head>
<body>
{@$songyu@}<br/>
{@$zhangyuan@}
</body>
</html>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁武县| 金寨县| 青铜峡市| 开平市| 宝兴县| 河间市| 静乐县| 大悟县| 璧山县| 衡南县| 廊坊市| 疏勒县| 年辖:市辖区| 吉林省| 铁岭县| 万山特区| 广州市| 加查县| 尼玛县| 上林县| 唐河县| 饶平县| 泸定县| 剑川县| 上栗县| 龙州县| 象州县| 昌乐县| 安顺市| 仁怀市| 祁东县| 临猗县| 加查县| 孝昌县| 伊宁县| 扶余县| 闸北区| 大英县| 正安县| 湘阴县| 钟祥市|