This article mainly introduces the example code of pure static page in PHP. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor and take a look
1. First look at the following code index.PHP
<?php // 准备要展示到网页的数据 $data = array( array('id'=>1,'msg'=>'hello java'), array('id'=>2,'msg'=>'hello php'), array('id'=>3,'msg'=>'hello python'), ); // 渲染到模板 // 实际项目一般是在html里渲染 // 这里演示 希望能看懂 foreach($data as $item){ echo $item['id'].'===>'.$item['msg'].'<br/>'; }
We can imagine accessing index.php What kind of page effect is it, but this is not the purely static page we want.
We have already learned the principle of page staticization in PHP: http://www.jb51.net/article/116811.htm
Let’s implement it and see. What code needs to be changed.
<?php // 准备要展示到网页的数据 $data = array( array('id'=>1,'msg'=>'hello java'), array('id'=>2,'msg'=>'hello php'), array('id'=>3,'msg'=>'hello python'), ); // 渲染到模板 // 实际项目一般是在html里渲染 // 这里演示 希望能看懂 ob_start(); // 开始输入缓冲控制 foreach($data as $item){ echo $item['id'].'===>'.$item['msg'].'<br/>'; } // 开始生成静态页面文件 if(file_put_contents('index.html',ob_get_contents())){ echo 'success'; }else{ echo 'error'; }
After execution, an index.html file will be generated. This is the static page we really need.
index.html content is as follows:
1===>hello java
2===>hello php
3== =>hello python
Then when we access index.html in the browser, the content displayed is the same as when we initially accessed index.php, but the difference is that index.html is a static page.
The above is the entire content of this article, I hope it will be helpful to everyone's study.
php code implementationPurely static page
php page staticization - the principle of achieving pure static
## Static to KVDB_html/css_WEB-ITnose
The above is the detailed content of How to implement pure static page in php. For more information, please follow other related articles on the PHP Chinese website!