-
- $con = array(array("newtitle","newcontent"),array("newtitle2","newcontent2"));
- foreach($con as $id=>$val)
- {
- $title = $val[0];
- $content = $val[1];
- $path = $id.'.htm';
- $fp = fopen("jia.htm", "r"); //打开文件,只读方式
- $str = fread($fp, filesize("jia.htm")); //读取文件
- $str = str_replace("{title}", $title,$str); //将字符串中的内容进行替换
- $str = str_replace("{content}", $content, $str);
- fclose($fp); //关闭文件
-
- $fpw = fopen($path, "w"); //以写入的方式打开文件
- fwrite($fpw, $str); //将$str写入文件
- fclose($fpw);
- echo "generate successfully!";
- }
- ?>
复制代码
|