The ob_start () function is used to open the buffer. For example, if there is output before the header () function, including carriage return, space, line feed, and "Header had all ready send by" errors, in this case, you can use ob_start () to open the data block of the PHP code in the buffer zone and echo () to output the data in the buffer zone rather than immediately. of course, opening a buffer has a lot to do, as long as you can make full use of your imagination. the following four points can be summarized:
1. used before header ()
Ob_start (); // open the buffer
Echo/"Hellon/"; // output
Header ("location: index. php"); // redirects the browser to index. php.
Ob_end_flush (); // output all content to the browser
?>
2. The phpinfo () function can obtain information on the client and server, but it is best to save the client information using the buffer method.
Ob_start (); // open the buffer
Phpinfo (); // use the phpinfo Function
$ Info = ob_get_contents (); // obtain the buffer content and assign it to $ info
$ File = fopen (/'info.txt/',/'W/'); // open the info.txt file.
Fwrite ($ file, $ info); // write the information to info.txt
Fclose ($ file); // close the info.txt file
?>
3. Static Page Technology
Ob_start (); // open the buffer
?>
All php page output
$ Content = ob_get_contents (); // Retrieves all the content output on the php page.
$ Fp = fopen ("output00001.html", "w"); // create a file, open it, and write
Fwrite ($ fp, $ content); // write the content of the PHP page into output00001.html, and then ......
Fclose ($ fp );
?>
4. Output code
Function run_code ($ code ){
If ($ code ){
Ob_start ();
Eval ($ code );
$ Contents = ob_get_contents ();
Ob_end_clean ();
} Else {
Echo "error! No output ";
Exit ();
}
Return $ contents;
}