PHP头条
热点:

php生成静态页html页面代码


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

www.phpzy.comtrue/phprm/25399.htmlTechArticlephp生成静态页html页面代码 ?php header(Content-type:text/html;charset=utf-8); if(!function_exists(file_get_contents)){ //如果系统没有file_get_contents()函数 function file_get_contents($file){ //自己写file_get_contents()函数...

相关文章

    暂无相关文章

PHP之友评论

今天推荐