PHP experience -- output buffer processing functions: ob_start, ob_get_contents, ob_end_clean, ob_end_flush

Source: Internet
Author: User

The function of the output buffer processing function is similar to the C stack. It is temporarily put into a bucket to process the content.

The output buffer functions include:

    • Ob_start ()-Enable Output Control Buffer
    • Ob_get_length ()-return the length of the output buffer.
    • Ob_get_level ()-return the nested level of the output buffer
    • Ob_get_status ()-return the status of the output buffer (returned in array format. The top-level is returned by default. If the parameter is true, all values are returned)
    • Ob_get_contents ()-return the content of the output buffer
    • Ob_get_clean ()-returns the current output buffer in string format and closes the output buffer
    • Ob_end_clean ()-clear (erase) the buffer and disable the output buffer.
    • Ob_get_flush ()-return the output buffer content with a string and disable the buffer
    • Ob_end_flush ()-washed out (sent) output buffer content Buffer

Example:

<? PHP  Define ('App _ root ', Dirname ( _ File __  ));  $ File = '/Templates/html/error_config.html' ;  Ob_start  ();  Include (App_root. $ File  );  Ob_end_flush  (); //  $ Contents = ob_get_contents (); this saves the output and can be further processed.  // Ob_end_clean ();     //  Echo $ contents; ?>
 <?PHP echo "<? XML version = \ "1.0 \" encoding = \ "UTF-8 \"> ";?>   <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >   < Html  Xmlns  = "Http://www.w3.org/1999/xhtml"  >   <  Head  >       <  Meta  HTTP-equiv  = "Content-Type"  Content  = "Text/html; charsets = UTF-8"   />       <  Meta HTTP-equiv  = "Content-script-type"  Content  = "Text/JavaScript"   />       <  Meta  HTTP-equiv  = "Content-style-type"  Content  = "Text/CSS"   />       <  Title  > Error </ Title  >   </  Head  >   <  Body  Onload  = "Doredirect ()"  >   <  H1  > Error </  H1  >   < Div  Style  = "Position: absolute; top: 150px; text-align: center; width: 95% ;"  >       <  P  Style  = "Margin: 12pt ;"  > <  Strong  > Config. php </  Strong  > Does not exist or is not readable by the webserver in the directory.</  P  >       <  P  Style  = "Margin: 12pt ;"  >  <?PHP echo commonfunctions: $ psi_version_string?>  </  P  >   </  Div  >  </  Body  >   </  Html  >  

The output result is as follows:

 
Config. php does not exist or is not readable by the webserver in the phpsysinfo directory.

 

 

 

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.