Home > Article > Backend Development > PHP uses ob_start to generate html pages, phpob_start_PHP tutorial
The example in this article describes how PHP uses ob_start to generate html pages. Share it with everyone for your reference. The specific method analysis is as follows:
ob_start([string output_callback]) - Open the output buffer
All output information is no longer sent directly to the browser, but is saved in the output buffer. An optional callback function is used to process the output result information.
ob_end_flush - End (send) the contents of the output buffer, close the output buffer
Using the output control function allows us to freely control the output of data in the script, which is useful when we want to output before the header.
I hope this article will be helpful to everyone’s PHP programming design.
It’s very simple, use ob_start to suppress it, and then save it to an html page. I wrote a small demonstration
Add parameters at the end when accessing? id=xxx xxx is any number, you can replace the output inside Your dynamic page is enough, there are explanations in the code
ob_start();
/*The following content is your original dynamic page*/
$id=isset($_GET["id"])?$_GET["id"]:'';
if ($id!=''){
echo "Original page parameters using parameters Generated$id.html";
}
/*End* for ".$id." /
$info=ob_get_contents();
$file=fopen($id.'.html','w');
fwrite($file,$info);
fclose($file);
?>
The following three methods can be used:
1. Use hyperlinks to connect text
You can also add " ?id=idvalue&cate=catevalue" and so on to pass the necessary parameters to test.php. In test.php, you can use $_GET[id] and $_GET[cate] (or $_REQUEST[id] and $_REQUEST[cate]) Get the value of the parameter.
2. Use the form to submit