----------code-----------
<?php
if (empty($_GET['tpl'])) exit('?tpl=temp name');
$html = insert(tpl($_GET['tpl']));
$html = str_replace('{CSS_PATH}', 'http://phpcms.q/statics/css/', $html);
$html = str_replace('{IMG_PATH}', 'http://phpcms.q/statics/images/', $html);
$html = str_replace('{JS_PATH}', 'http://phpcms.q/statics/js/', $html);
echo $html;
function insert($file) {
$txt = get_include_contents($file);
$split = preg_split("/(\{template +[\"'][^\"']+[\"'] *, *[\"'][^\"']+[\"']\})/", $txt, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE);
if (count($split) > 1) {
foreach ($split as $key => $tmp) {
if (preg_match("/\{template +[\"'][^\"']+[\"'] *, *[\"']([^\"']+)[\"']\}/", $tmp, $match)) {
$split[$key] = insert(tpl($match[1]));
}
}
return implode('', $split);
} else {
return $txt;
}
}
function tpl($name) {
$name = './phpcms/templates/chrd/content/'.$name.'.html';
if (! file_exists($name)) {
exit('包含出错,文件不存在:' + $name);
}
return $name;
}
function get_include_contents($filename) {
if (is_file($filename)) {
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
return false;
}
------------说明-------
只要是为了方便按phpcms的模板存放安排显示模板的html效果,而不需要使用平台的生成功能后再查看生成页,这个功能实现就很容易的对include和某些变量自己写解释功能.