看了一些开源系统的,简单的总结一下php的模板及静态原理。
先贴代码,再做解释。
index.php
- <?php
- if(file_exists(‘index.html‘))
- {
- echo file_get_contents(‘index.html‘);
- }
- else
- {
-
- $var = "Hello,World.";
-
- ob_start();
-
- require_once(‘template.php‘);
-
- $out = ob_get_contents();
-
- file_put_contents(‘index.html‘,$out);
-
- ob_end_flush();
- }
template.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=utf-8" />
- <title>HTML</title>
- </head>
- <body>
- <hr/>
- <p>
- <?php echo $var;?>
- </p>
- <hr/>
- </body>
- </html>
代码解释见注释。
转自http://baiyuxiong.iteye.com/blog/796644
php模版静态化原理
原文:http://www.cnblogs.com/liuwenbohhh/p/4380576.html