PHP uses the ob_start method to generate html pages, phpob_start. PHP uses ob_start to generate html pages. phpob_start this article describes how PHP uses ob_start to generate html pages. Share it with you for your reference. The specific method analysis is as follows: PHP uses the ob_start method to generate html pages, phpob_start
This example describes how PHP uses ob_start to generate html pages. Share it with you for your reference. The specific method is analyzed as follows:
Ob_start ([string output_callback])-open the output buffer
All output information is not directly sent to the browser, but saved in the output buffer. an optional callback function is used to process output result information.
Ob_end_flush-end (SEND) output buffer content, disable the output buffer
The output control function allows you to freely control the output of data in the script, which is useful when we want to output data before the header.
The code is as follows:
<? Php
Ob_start (); // open the buffer
Echo "output n"; // output
Header ("header information ");
Ob_end_flush (); // output all content to the browser
?>
Most people use ob when generating static html, when a page is not refreshed, when other users browse this page again, the program will no longer call php and related database tutorials. In this case, using ob to generate html is a good practice.
The code is as follows:
<? Php
Ob_start ();
If (@ readfile ($ tem_path) {// write the content in the specified path to the cache. If not, false is returned (that is, a PHP file you want to convert to html)
$ Content = ob_get_contents (); // Obtain the cached content.
$ Fp = fopen ("1.html", "w"); // create a file, open it, and write
Fwrite ($ fp, $ content); // write the content of the PHP page to 1.html
}
Fclose ($ fp );
Ob_clean ();
?>
I hope this article will help you with PHP programming.
How does php generate detailed code for generating HTML pages?
It's easy to press it with ob_start and save it to an html page. I wrote a small demonstration.
What parameters are added after the access? Id = xxx is any number. you can replace the output in it with your dynamic page. the code provides an explanation.
Ob_start ();
/* The following content is your original dynamic page */
$ Id = isset ($ _ GET ["id"])? $ _ GET ["id"]: '';
If ($ id! = ''){
Echo "the page parameter of the original parameter is". $ id. "</br> generated id.html </a> ";
}
/* End */
$ Info = ob_get_contents ();
Using file1_fopen(id.'.html ', 'w ');
Fwrite ($ file, $ info );
Fclose ($ file );
?>
After PHP generates HTML, how can it link to the page?
You can use the following methods:
1. use hyperlinks to connect text </a>
You can also add "? Id = idvalue & cate = catevalue "to test. php passes necessary parameters in test. in php, you can use $ _ GET [id] and $ _ GET [cate] (or $ _ REQUEST [id] and $ _ REQUEST [cate]) to obtain the parameter values.
2. use form submission
Form Content </form>
Here, the method can be GET (test. php, obtain the parameter such as 1; it can also be POST, GET the parameter similar to 1, but change GET to POST, the REQUEST is common)
3. use ajax technology.
In addition, the frame technology in html can be used.
Examples in this article describes how PHP uses ob_start to generate html pages. Share it with you for your reference. The specific method is analyzed as follows :...