- Ob_start (); #开启服务器缓存
- Include_once ' index.php ';
- $ctx =ob_get_contents (); #获取缓存
- Ob_end_clean (); #清空缓存
- $FH =fopen ("index.html", "w+");
- Fwrite ($FH, $ctx); #写入html, generating HTML
- Fclose ($FH);
- ?>
Copy CodeMethod 2:php static file generation class
- Class createhtml
- {
- function mkdir ($prefix = ' article ')
- {
- $y = date (' Y ');
- $m = Date (' m ');
- $d = Date (' d ');
- $p =directory_separator;
- $filePath = ' article '. $p. $y $p. $m. $p. $d;
- $a =explode ($p, $filePath);
- foreach ($a as $dir)
- {
- $path. = $dir. $p;
- if (!is_dir ($path))
- {
- Echo ' does not have this directory '. $path;
- mkdir ($path, 0755);
- }
- }
- return $filePath. $p;
- }
- function Start ()
- {
- Ob_start ();
- }
- Function End ()
- {
- $info = Ob_get_contents ();
- $fileId = ' 12345 ';
- $postfix = '. html ';
- $path = $this->mkdir ($prefix = ' article ');
- $fileName = Time (). ' _ '. $fileId. $postfix;
- $file =fopen ($path. $fileName, ' w+ ');
- Fwrite ($file, $info);
- Fclose ($file);
- Ob_end_flush ();
- }
- }
- ?>
- $s =new createhtml ();
- $s->start ();
- ?>
- Asdfasdfasdfasdfasdfasdfasdfasdfasdf
- Adfasdfasdf
- >
- $s->end ();
- ?>
Copy CodeAttached: 1, flush: Flush the contents of the buffer, output. function format: Flush () Description: This function is often used and is highly efficient. 2, Ob_start: Open output buffer function format: void Ob_start (void) Description: When the buffer is activated, all non-file header information from the PHP program is not sent, but is saved in the internal buffer. In order to output the contents of the buffer, you can use the contents of the Ob_end_flush () or flush () output buffers. 3. Ob_get_contents: Returns the contents of the internal buffer. Use function Format: string ob_get_contents (void) Description: This function returns the contents of the current buffer and returns FALSE if the output buffer is not activated. 4. Ob_get_length: Returns the length of the internal buffer. Usage: int ob_get_length (void) Description: This function returns the length in the current buffer, as in ob_get_contents if the output buffer is not active. FALSE is returned. 5. Ob_end_flush: Sends the contents of the internal buffer to the browser, and closes the output buffer. Method of Use: void Ob_end_flush (void) Description: This function sends the contents of the output buffer, if any. 6. Ob_end_clean: Delete the contents of the internal buffer and close the internal buffer use method: void Ob_end_clean (void) Description: This function does not output the contents of the internal buffer but deletes it! 7. Ob_implicit_flush: Open or close the absolute refresh using method: void Ob_implicit_flush ([int flag]) you may be interested in the article:three ways to generate static pages in PHP and the code in detail PHP generates static page functions (php2html) example PHP method for generating static pages (three functions) The template of PHP generated static files and cache PHP write a static page generated on the class virtual host on a regular basis to automatically generate static pages of PHP static pages in a detailed tutorial on how to generate a static HTML file in PHP Smarty method to generate static pages learn how PHP generates static HTML files. PHP generation static Method of the page PHP three ways to generate a static HTML file |