当前位置:Gxlcms > PHP教程 > php生成静态html_PHP教程

php生成静态html_PHP教程

时间:2021-07-01 10:21:17 帮助过:4人阅读

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 "
";
echo $_SERVER['DOCUMENT_ROOT'];
echo "
";
echo $_SERVER['PHP_SELF'];
echo "
";
echo date('ymd');
echo "
";
echo dirname($_SERVER['PHP_SELF']);
?>










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 "
";
echo $_SERVER['DOCUMENT_ROOT'];
echo "
";
echo $_SERVER['PHP_SELF'];
echo "
";
echo date('ymd');
echo "
";
echo dirname($_SERVER['PHP_SELF']);
?>









[html] //tmp.html



{title}


{content}



摘自 chaojie2009的专栏

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478380.htmlTechArticle?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,$cont...

人气教程排行