PHP静态文件生成类

  1. <?php
  2. class CreateHtml
  3. {
  4. function mkdir( $prefix= 'article' )
  5. {
  6. $y = date('Y');
  7. $m = date('m');
  8. $d = date('d');
  9. $p=DIRECTORY_SEPARATOR;
  10. $filePath='article'.$p.$y.$p.$m.$p.$d;
  11. $a=explode($p,$filePath);
  12. foreach ( $a as $dir)
  13. {
  14. $path.=$dir.$p;
  15. if(!is_dir($path))
  16. {
  17. //echo '没有这个目录'.$path;
  18. mkdir($path,0755);
  19. }
  20. }
  21. return $filePath.$p;
  22. }
  23. function start()
  24. {
  25. ob_start();
  26. }
  27. function end()
  28. {
  29. $info = ob_get_contents();
  30. $fileId = '12345';
  31. $postfix = '.html';
  32. $path = $this->mkdir($prefix= 'article');
  33. $fileName = time().'_'.$fileId.$postfix;
  34. $file=fopen($path.$fileName,'w ');
  35. fwrite($file,$info);
  36. fclose($file);
  37. ob_end_flush();
  38. }
  39. }
  40. ?>
  41. <?php
  42. $s=new CreateHtml();
  43. $s->start();
  44. ?>
  45. <html>
  46. <body>
  47. asdfasdfasdfasdfasdfasdfasdfasdfasdf<br>
  48. adfasdfasdf<br>
  49. </body>>
  50. </html>
  51. <?php
  52. $s->end();
  53. ?>