Questions about ob_start.

Source: Internet
Author: User
Ob_start describes this in the manual: This function will enable the output buffer. When the output buffer is activated, the script does not output content (except the http header). On the contrary, the content to be output is stored in the internal buffer. According to my understanding, {code...} and the manual... ob_start are described as follows:

This function enables the output buffer. When the output buffer is activated, the script does not output content (except the http header). On the contrary, the content to be output is stored in the internal buffer.

According to my understanding, this is the case:


  

Why is it different from what is described in the manual.

Reply content:

Ob_start is described in the manual as follows:

This function enables the output buffer. When the output buffer is activated, the script does not output content (except the http header). On the contrary, the content to be output is stored in the internal buffer.

According to my understanding, this is the case:


   

Why is it different from what is described in the manual.

It should be understood that it will not be immediately output to the upper-level buffer. you can use the relevant operations of ob _ * to obtain, rush out, and clear the buffer. at this time, the output can be unified, such as regular processing, data packaging.

For static pages, you can use the ob cache technology provided by php to manually process cache content submitted by apche and other servers.

$ Id = isset ($ _ GET ['id'])? $ _ GET ['id']-0: 0; $ filename = "html /". date ("Ymd "). "/news-id ". $ id. ". html "; if (! File_exists ("html/". date ("Ymd") {mkdir ("html/". date ("Ymd");} echo $ filename; if (! File_exists ($ filename) | filemtime ($ filename) + 60
    
     
Query ($ SQL); $ row = $ res-> fetch_assoc (); if ($ row) {echo"
     
    
      "; Echo" 
     
        "; Echo" 
       "; Echo" 
       "; Echo" 
       "; Echo" 
      "; Echo" 
      
        "; Echo" 
       "; Echo" 
       "; Echo" 
       "; Echo" 
      "; Echo" 
     
IDTitleContent
". $ Row ['id']."". $ Row ['title']."". $ Row ['content']."
";}Else {echo" no data ";}$ content = ob_get_contents (); ob_end_clean (); file_put_contents ($ filename, $ content);} require $ filename;

That's because your script has been executed.
The buffer is output.
You can add ob_end_clean () next to echo ();
The buffer will be cleared.

That's strange if you don't want to output it... Ob only allows us to get the rendering result of php and use it for caching.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.