<?phpecho ‘hello100‘;header(‘content-type:text/html;charset=utf-8‘);echo ‘hello200‘;
Solution:
1.把heander()信息放在头部2.打开 ob 缓冲
How to open the OB cache:
1.在 php.ini 中打开2. ob_start()
ob1.php
<?php //open OB cache ob_start (); echo ' hello100 ' ; header ( content-type:text/html;charset= Utf-8 ' ); echo ' hello200 ' ; echo ' hello300 ' ; //gets the data of the OB cache $str = Ob_get_contents (); //save $str to File file_put_contents (, Span class= "hljs-variable" > $str ); echo ' hello400 ' ; echo ' hello500 ' ; echo ' hello600 ' ;
Wjh.log
hello100hello200hello300
several principles:
Situation cache:
<?php//Open OB cacheOb_start ();Echo ' hello100 '; Header (' Content-type:text/html;charset=utf-8 ');Echo ' hello200 ';Echo ' hello300 ';//Empty OB cacheOb_clean ();//Get OB-Cached data$str= Ob_get_contents ();//Save the $STR to a fileFile_put_contents (' Wjh.log ',$str);Echo ' hello400 ';Echo ' hello500 ';Echo ' hello600 ';
<?php//Open OB cacheOb_start ();Echo ' hello100 '; Header (' Content-type:text/html;charset=utf-8 ');Echo ' hello200 ';Echo ' hello300 ';//Empty OB cache//ob_clean ();//The function is to empty the data in the OB and close the OB cacheOb_end_clean ();Echo ' hello400 ';//Get OB-Cached data$str= Ob_get_contents ();//Save the $STR to a fileFile_put_contents (' Wjh.log ',$str);Echo ' hello500 ';Echo ' hello600 ';
<?php//Open OB cacheOb_start ();Echo ' hello100 '; Header (' Content-type:text/html;charset=utf-8 ');Echo ' hello200 ';Echo ' hello300 ';//Empty OB cache//ob_clean ();//The function is to empty the data in the OB and close the OB cache//ob_end_clean ();Ob_clean ();Echo ' hello400 ';//Get OB-Cached data$str= Ob_get_contents ();//Save the $STR to a fileFile_put_contents (' Wjh.log ',$str);Echo ' hello500 ';Echo ' hello600 ';
<?php//开启ob缓存ob_start();echo‘hello100‘;header(‘content-type:text/html;charset=utf-8‘);echo‘hello200‘;//把 ob 缓存的数据,刷新到程序缓存 ,并关闭echo‘hello300‘;$str = ob_get_contents();file_put_contents(‘wjh.log‘,$str//所以文件为空echo‘hello500‘;echo‘hello600‘;
<?php//Open OB cacheOb_start ();Echo ' hello100 '; Header (' Content-type:text/html;charset=utf-8 ');Echo ' hello200 ';//Put the OB cache data, flush it to the program cache, and close//ob_end_flush ();//Set OB cache data, flush to program cache, do not closeOb_flush ();Echo ' hello300 ';$str= Ob_get_contents (); File_put_contents (' Wjh.log ',$str);//So the file is emptyEcho ' hello500 ';Echo ' hello600 ';
2. Caching mechanisms