模板页面是 :<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{*$title*}</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="{*$keywords*}" />
<meta name="description" content="{*$description*}" />
.......生成模板页面:$title="静态首页生成";
$keywords="fdsfdsfds";
$description="fdsfdsfdsdddd";$moban_index = "templates/index.html";
$fp=fopen($moban_index,"r"); //读取首页模板内容
$str=fread($fp,filesize($moban_index));//filesize($moban_index)
fclose($fp);那么就是这里要有个标签替换的函数
本来正常情况下,用
$str=str_replace("{*$title*}",$title,$str);
... 是可以全部替换掉的,但是这样每一个都要去替换就比较麻烦了,有没高手给出一个函数就是让变量自动匹配标签,因为标签里面本身就是存在变量名的,无非就是通过preg_match_all()函数给他取出来,然后他自动匹配其函数的值
$fp=fopen("index.html","w"); //写入文件
fwrite($fp,$str);
fclose($fp);