PHP uses Ob_start to generate HTML page methods, Phpob_start
This example describes how PHP uses Ob_start to generate HTML pages. Share to everyone for your reference. The specific methods are analyzed as follows:
Ob_start ([string output_callback])-Open output buffer
All output information is not sent directly to the browser, but is stored in the output buffer, the optional callback function is used to process the output information.
Ob_end_flush-End (send) the contents of the output buffer, close the output buffer
Using the output control function allows you to freely control the outputs of the data in the script, which is useful when we want to output it before the header.
Copy the Code code as follows: <?php
Ob_start (); Open buffer
echo "Output n"; Output
Header ("header information");
Ob_end_flush ();//output all content to the browser
?>
The majority of personal use OB is when generating static HTML, when a page is no longer refreshed, and when other users are browsing this page again, the program will no longer invoke PHP and related database tutorials. This is a good way to generate HTML using an OB.
Copy the Code code as follows: <?php
Ob_start ();
if (@readfile ($tem _path)) {//writes the contents of the specified path to the cache. If there is no return False (a PHP file that you want to convert to HTML)
$content = Ob_get_contents (); Get the content in the cache
$fp = fopen ("1.html", "w"); Create a file, and open it, ready to write
Fwrite ($fp, $content); Write the contents of the PHP page to 1.html
}
Fclose ($FP);
Ob_clean ();
?>
I hope this article is helpful to everyone's PHP programming.
PHP how to generate HTML page to detailed build process code
Very simple, with Ob_start suppressed, and then saved to an HTML page can be, wrote a small demo
Add parameters after access? id=xxx XXX for any number, you can change the output of the inside to your dynamic page, the code has an explanation
Ob_start ();
/* The content below is your original dynamic page */
$id =isset ($_get["id"])? $_get["id"]: ';
if ($id! = ") {
echo "The original use parameter of the page parameter is". $id. " </br> has generated $id.html</a> ";
}
/* END */
$info =ob_get_contents ();
$file =fopen ($id. HTML ', ' W ');
Fwrite ($file, $info);
Fclose ($file);
?>
How to link to the page after PHP generates HTML
There are three main ways to do this:
1. Connect Text with hyperlink </a>
You can also add "? Id=idvalue&cate=catevalue" after test.php to pass the necessary parameters to test.php, $_get[id] and $_get[cate in test.php) (or $_ Request[id] and $_request[cate]) to get the value of the parameter.
2. Submit using Forms
Here the method can be get (test.php, get parameters such as 1, or post, get parameters like 1, but to change get to Post,request Universal)
3, the use of Ajax technology.
In addition, you can take advantage of frame technology in HTML.
http://www.bkjia.com/phpjc/907839.html www.bkjia.com True http://www.bkjia.com/phpjc/907839.html techarticle php using Ob_ Start the method of generating HTML pages, Phpob_start This example describes how PHP uses Ob_start to generate HTML pages. Share to everyone for your reference. The specific method is analyzed as follows: ...