Home  >  Article  >  php教程  >  php生成静态页html页面代码

php生成静态页html页面代码

WBOY
WBOYOriginal
2016-06-13 10:38:38896browse

  1. header(Content-type:text/html;charset=utf-8);
  2. if(!function_exists(file_get_contents)){ //如果系统没有file_get_contents()函数
  3. function file_get_contents($file){ //自己写file_get_contents()函数
  4. $fp = fopen($file,r);
  5. $content = fread($fp,filesize($file));
  6. fclose($fp);
  7. return $content;
  8. }
  9. }
  10. $tmp_file = template.html; //模板文件
  11. $content = file_get_contents($tmp_file); //获得模板文件内容
  12. $title = title; //模板变量title要替换的值
  13. $text = text; //模板变量text要替换的值
  14. $content = str_replace(,$title,$content); //替换模板变量title
  15. $content = str_replace(,$text,$content); //替换模板变量text
  16. //echo $content; //显示替换后的模板文件内容
  17. MakeHtml(news.html,$content);//写入生成后的静态文件内容到news.html文件
  18. echo 查看文件;
  19. function MakeHtml($file,$content){
  20. $fp = fopen($file,w);
  21. fwrite($fp,$content);
  22. fclose($fp);
  23. }
  24. ?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn