简单
php 教程模板引擎的实现例子
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
</head>
<body>
{$var}
<br />
{loop $arr $v}
{$v} |
{/loop}
</body>
</html>
index.php 调用文件
<?php
header("content-type:text/html; charset=utf-8");
require_once "./include/common.inc.php";
$var = 'abc';
$arr = array(1, 2, 3);
include template('index');
?>
/common.inc.php 文件
<?php
define('in_site', true);
define('site_root', substr(dirname(__file__), 0, -7));
require_once site_root.'./include/template.func.php';
$tplrefresh = 1; //设置是否检查更新
$tpldir = site_root.'./templates/default/'; //模板存放目录
$objdir = site_root.'./sitedata/templates/'; //模板编译文件存放目录
?>
template.func.php 文件
<?
if(!defined('in_site')) {
exit('access denied!');
}
function checktplrefresh($tplfile, $timecompare) {
global $tplrefresh;
if($tplrefresh == 1 && @filemtime($tplfile) != $timecompare) {
parse_template($tplfile);
}