php 生成静态html
<?phprequire "comm.php";
if(isset($_POST['submit'])){
$title=$_POST['title'];
$content=$_POST['content'];
$addtime=time();
$sql="insert into news (title,content,addtime) values ('$title','$content','$addtime')";
$rs=$db->query($sql);
if($rs){
$time=date('ymd');
$tmp=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/'.$time.$title.'.'.html;
$fp=fopen($tmp,'w');
$tmpT=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/tmp.html';
$fpT=fopen($tmpT,'r');
$str=fread($fpT,filesize($tmpT));
$str=str_replace('{title}',$title,$str);
$str=str_replace('{content}',$content,$str);
fwrite($fp,$str);
fclose($fp);
fclose($fpT);
echo "OK";
}
}
//==================================
echo "<br>";
echo $_SERVER['DOCUMENT_ROOT'];
echo "<br>";
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo date('ymd');
echo "<br>";
echo dirname($_SERVER['PHP_SELF']);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<form method="post" action="">
新闻标题:<input type="text" name="title"><br />
新闻内容:<textarea name="content"></textarea><br />
<input type="submit" name="submit" value="提交">
</form>
</body>
</html>
<?php
require "comm.php";
if(isset($_POST['submit'])){
$title=$_POST['title'];
$content=$_POST['content'];
$addtime=time();
$sql="insert into news (title,content,addtime) values ('$title','$content','$addtime')";
$rs=$db->query($sql);
if($rs){
$time=date('ymd');
$tmp=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/'.$time.$title.'.'.html;
$fp=fopen($tmp,'w');
$tmpT=$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/tmp.html';
$fpT=fopen($tmpT,'r');
$str=fread($fpT,filesize($tmpT));
$str=str_replace('{title}',$title,$str);
$str=str_replace('{content}',$content,$str);
fwrite($fp,$str);
fclose($fp);
fclose($fpT);
echo "OK";
}
}
//==================================
echo "<br>";
echo $_SERVER['DOCUMENT_ROOT'];
echo "<br>";
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo date('ymd');
echo "<br>";
echo dirname($_SERVER['PHP_SELF']);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<form method="post" action="">
新闻标题:<input type="text" name="title"><br />
新闻内容:<textarea name="content"></textarea><br />
<input type="submit" name="submit" value="提交">
</form>
</body>
</html>
[html] //tmp.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>{title}</title>
</head>
<body>
{content}
</body>
</html>
摘自 chaojie2009的专栏
补充:Web开发 , php ,