首頁  >  文章  >  後端開發  >  php產生html檔案的簡單例子

php產生html檔案的簡單例子

WBOY
WBOY原創
2016-07-25 09:03:54885瀏覽
  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