虽然成功了!但很多地方还是不明白~贴上来请教大家!
index.html
代码:
<html>
<head>
<title>{title}</title>
</head>
<body>
{main}
</body>
</html>
<?php
代码:
function template($skin){
$data=file_get_contents($skin);
$str = preg_replace('/{([a-zA-Z]+)}/','<?php echo $GLOBALS[\'\\1\']; ?>',"\r\n?>\r\n".$data."\r\n<?php\r\n");
return eval($str);
}
$title='标题';
$main='内容';
template('index.html');
?>
上面这个只能index.php和index.html在同一个目录才行!
如果想把index.html放到其他的目录就出错了!
引用:
| Fatal error: main(): Failed opening required '' (include_path='.;c:\php4\pear') in D:\wwwroot\index.php on line 16 |
代码:
function template($file, $temdir){
$path = YEDOO_ROOT."./templates/".$temdir."/".$file.".".htm;
if (!file_exists($path)) {
$path = YEDOO_ROOT."./templates/default/".$file.".".htm;
$path = YEDOO_ROOT.'.'.$temdir'.$file.'.'.htm;
}
$data =file_get_contents($path);
$str = preg_replace('/{([a-zA-Z]+)}/','<?php echo $GLOBALS[\'\\1\']; ?>',"\r\n?>\r\n".$data."\r\n<?php\r\n");
// $str = preg_replace("/\{(\\\$[a-zA-Z0-9_\[\]\'\"\$\.\x7f-\xff]+)\}/s", "<?=\\1?/>", $str);
return eval($str);
}








一个简单的php程序与模版分离的实现方法~有待指正!

独乐乐不如众乐乐










平板模式