hi
Being myself again last night, I couldn’t sleep well and my whole body felt bad. . .
1. PHP realizes page staticization
2. Pure static
2.2 The principle of realizing pure static page
--Basic method
file_put_contents() function;
Use PHP’s built-in caching mechanism, output_buffering.
Detailed information can be found in the php manual. Focus on function format, parameters, and return values.
--Lizi file_put_contents()
/*
* Write function
*/
file_put_contents('index.shtml','asdklfj');
Run http://localhost/phpJingtaihua/index.shtml and get the result. A very simple function.
--Lizi output_buffering
There are built-in functions, ob (output_buffering) series.
Mainly involves four
ob_start, open the output control buffer;
ob_get_contents, returns the output buffer content;
ob_clean, clear the output buffer;
ob_get_clean, get the buffer content and delete the current output buffer.
ob_start(); //Open buffer
echo 1234;
echo ob_get_contents();
Get the sequence of 12341234. That is, all output goes through the buffer - like a filter on the faucet.
ob_start(); //Open buffer
echo 111;echo "
";
echo ob_get_contents();echo "
";
ob_clean();
echo ob_get_contents();echo "
";
echo 222;echo "
";
echo ob_get_clean();echo "
";
Here, 111 will no longer be output because of the buffer clearing, even the original echo statement will not work.
2.3 Introduction to pure static case implementation
The ultimate goal is to generate static files.
First, write data to static files.
Second, use the ob mechanism to obtain data (that can be written to static files).
2.4 Case implementation steps
Link to the database and obtain data from the database -> Fill the obtained data into the template file -> Convert dynamic pages into static pages and generate pure static files.
-----------------
This is it for now, I will write it later if I have time at night. . . .