1, Ob_start ()
Turn on file caching
2, Ob_get_contents ()
Get the memory in the cache
3, Ob_get_length ()
Get the length of the buffer zone
4, Ob_flush ()
The contents of the output buffer, if you want to get the contents of the buffer to use ob_get_contents () before this function, otherwise the data will be emptied
5, Ob_end_flush ()
Output buffers and close cache
6, Ob_end_clean ()
Clears the cache and closes the output buffer, if this function is not executed after the Ob_start () is opened, the buffer will be written
Let's write a static example of the page to practice practiced hand, this case is based on the thinkphp framework to explain, other framework of the small partners of their own brain repair!
1, first there are four functions
Ob_start () Turn on caching
Ob_get_contents () Gets the contents of the buffer
Ob_clean () Delete the contents of the buffer
Ob_get_clean () gets and then deletes the buffer contents first
2. Then we define a function to generate the static file
/**定义一个缓存文件* @author crazy* @time 2018-03-14*/public function createCache(){$action = ACTION_NAME;$c_name = CONTROLLER_NAME;$dir = ‘./Cache/‘.$c_name.‘/‘.$action.‘/‘;if(is_dir($dir)){file_put_contents("$dir$action".‘.shtml‘,ob_get_contents());}else{if(mkdir($dir,0777,true)){file_put_contents("$dir$action".‘.shtml‘,ob_get_contents());}}}
3, according to the file directory exists and then we do the corresponding redirect
$action = ACTION_NAME;$c_name = CONTROLLER_NAME;$dir = ‘./Cache/‘.$c_name.‘/‘.$action.‘/‘.$action.‘.shtml‘;if(file_exists($dir)){header("Location:http://localhost/simengphp/$dir");}
4, local static
$.ajax({url:‘‘,type:‘get‘,dataType:‘json‘,error: function () {},success:function(data){$.each(data.result,function(key,val){})}});
We write this Ajax method of getting the page content in our template, and then when we call this page, this method automatically creates the
You should be in this position. Learn PHP (3)