The function of the output buffer processing function is somewhat similar to the C stack, which is temporarily placed in a storage space to process the content.
The output buffer functions are:
ob_start() - Open the output control buffer
ob_get_length() - Returns the length of the output buffer
##ob_get_level () - Returns the nesting level of the output buffer
ob_get_contents() - Returns the contents of the output buffer
ob_get_clean() - Returns the current output buffer in string format and closes output buffering
ob_end_clean () - Flushes (erases) the buffer and closes the output buffer
ob_get_flush() - Returns the output buffer contents as a string and closes the buffer
ob_end_flush() - Flush out (send out) the output buffer contents buffer
The example is as follows:
<?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(); 这样可以将输出保存,可以作进一步处理 //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; charset=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>
config.php does not exist or is not readable by the webserver in the phpsysinfo directory.
The above is the detailed content of PHP: Summary of output buffer processing function usage. For more information, please follow other related articles on the PHP Chinese website!