• php模版静态化原理


    看了一些开源系统的,简单的总结一下php的模板及静态原理。 
    先贴代码,再做解释。 
    index.php 

    Php代码  收藏代码
    1. <?php  
    2. //如果已存在静态页面,直接读取并显示  
    3. if(file_exists('index.html'))  
    4. {  
    5.     echo file_get_contents('index.html');  
    6. }  
    7. else  
    8. {  
    9.     //这里把需要的变量都附好值  
    10.     $var = "Hello,World.";  
    11.     //开启输出缓存  
    12.     ob_start();  
    13.     //这里调用模板,模板里嵌入一些PHP标签,用来显示变量的值  
    14.     require_once('template.php');  
    15.     //这里得到输出缓存,也就是调用模板后,将来要显示到页面上的内容  
    16.     $out = ob_get_contents();  
    17.     //把要显示的内容保存成一个文件  
    18.     file_put_contents('index.html',$out);  
    19.     //输出  
    20.     ob_end_flush();  
    21. }  


    template.php 

    Php代码  收藏代码
    1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    2. <html xmlns="http://www.w3.org/1999/xhtml">   
    3. <head>   
    4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
    5. <title>HTML</title>   
    6. </head>   
    7. <body>   
    8. <hr/>  
    9. <p>  
    10. <?php echo $var;?>  
    11. </p>  
    12. <hr/>  
    13. </body>  
    14. </html>  


    代码解释见注释。 

    转自http://baiyuxiong.iteye.com/blog/796644

  • 相关阅读:
    带你玩转Visual Studio——带你高效开发
    删除ue4中c++类
    ue4 2游戏构架相关
    UE4 代码总结
    unreal4特性介绍
    ue4 1官网编程指南总结
    UE4 中的 C++ 编程介绍
    ue4 代码入门
    Unity 5着色器系统代码介绍(下)
    Unity 5着色器系统代码介绍(上)
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/4380576.html
Copyright © 2020-2023  润新知