-
- ob_start();#Enable server cache
- include_once 'Index.php';
- $ctx=ob_get_contents();#Get cache
- ob_end_clean();#Clear cache
- $fh=fopen ("index.html","w+");
- fwrite($fh,$ctx);#Write html, generate html
- fclose($fh);
- ?>
Copy code
Method 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 'No such 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
- >
|