当前位置:编程学习 > php >>

php 生成静态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>  
  
<?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 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,