程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php 生成靜態html

php 生成靜態html

編輯:關於PHP編程

<?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的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved