首页 > 语言 > PHP > 正文

PHP静态文件生成类

2024-09-04 11:44:00
字体:大 中 小
来源:转载
供稿:网友
  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. ?> 

上一篇:PHP顶层类

下一篇:PHP分页类

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表