php生成html文件的简单例子

原创
2016-07-25 09:03:54 673浏览
  1. $con = array(array("newtitle","newcontent"),array("newtitle2","newcontent2"));
  2. foreach($con as $id=>$val)
  3. {
  4. $title = $val[0];
  5. $content = $val[1];
  6. $path = $id.'.htm';
  7. $fp = fopen("jia.htm", "r"); //打开文件,只读方式
  8. $str = fread($fp, filesize("jia.htm")); //读取文件
  9. $str = str_replace("{title}", $title,$str); //将字符串中的内容进行替换
  10. $str = str_replace("{content}", $content, $str);
  11. fclose($fp); //关闭文件
  12. $fpw = fopen($path, "w"); //以写入的方式打开文件
  13. fwrite($fpw, $str); //将$str写入文件
  14. fclose($fpw);
  15. echo "generate successfully!";
  16. }
  17. ?>
复制代码


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。