国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php生成靜態(tài)頁面的簡單示例

2024-05-04 23:22:55
字體:
供稿:網(wǎng)友

發(fā)布新聞,實(shí)現(xiàn)新聞頁面靜態(tài)化,真靜態(tài)


add.php

復(fù)制代碼 代碼如下:


<html>
 <head>添加新聞</head>

 <body>
   <form method="post" action="doadd.php">
     新聞標(biāo)題:<input type="text" size="100"><br>
     新聞內(nèi)容:<textarea cols="100" rows="25"></textarea><br>
     <input type="submit">
   </form>
 </body>
</html>

config.php

復(fù)制代碼 代碼如下:


<?php
 define("HOST", "localhost");
 define("USER", "justfan");
 define("PWD", "justfan");
 define("DB", "justfanDB");
 define("PORT", "3360");
?>

DB_class.php

復(fù)制代碼 代碼如下:


<?php
 class DB
 {
  private $host = '';
  private $uname = '';
  private $pwd = '';
  private $port = '';
  private $db = '';
     public static $instance = null;

  private function __construct($host , $uname , $pwd , $port , $db)
  {
   $this->host = $host;
   $this->uname = $uname;
   $this->port = $port;
   $this->pwd = $pwd;
   $this->db = $db;

   mysql_connect($host,$uname,$pwd);
   mysql_select_db($this->db);
  }

  public static function Instance()
  {
   if(Db::$instance==null){
    include 'config.php';
    return Db::$instance = new DB(HOST, USER, PWD, PORT, DB);
   } 
   else
    return Db::$instance;
  }

  public function query($sql)
  {
   mysql_query("SET NAMES UTF8");
   $query = mysql_query($sql) or die($sql." error");
   if(!$query) return false;
   else   return $query;
  }

  
  public function getAll($sql)
  {
   $query = $this->query($sql);
   if($query)
   {
    while($ret = mysql_fetch_assoc($query))
    {
     $result[] = $ret;
    }
   }   
   return $result;
  }

  
 }
?>

doadd.php

復(fù)制代碼 代碼如下:


<?php
include 'DB_class.php';
$db = DB::Instance();

$title=$_POST["title"];
$content=$_POST["content"];

$num = uniqid();
$houzui=".html";
$filename=date('Ymd').'http://m.survivalescaperooms.com/'.$num.$houzui;

$sql="insert into news(title,content,path) values ('{$title}' , '{$content}' , '{$filename}')";
$query = $db->query($sql);

$fp=fopen("model.htm","r");
$str=fread($fp,filesize("model.htm"));
$str=str_replace("{title}",$title,$str);
$str=str_replace("{content}",$content,$str);
fclose($fp);

$dir = dirname($filename);
if(!is_dir($dir)){
 mkdir($dir);
}

$handle=fopen($filename,"w");
fwrite($handle,$str);
fclose($handle);

 

echo "<a href={$filename} target=_blank>查看剛才添加的新聞</a>";
echo "<a href='add.php'>添加新聞</a>";
?>

model.htm

復(fù)制代碼 代碼如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
 <script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
 <link href="../bootstrap/css/bootstrap.min.css">
 <link href="../bootstrap/css/common.css">
 <title>{title}</title>
</head>
  <body>

    <div>
      <div>
        <h1>{title}</h1>
        <p>{content}</p>
      </div>
    </div>
  </body>
</html>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 响水县| 额尔古纳市| 望谟县| 通山县| 郑州市| 绥德县| 丁青县| 常山县| 平顺县| 蒙阴县| 阳信县| 横峰县| 恩施市| 华安县| 怀仁县| 喀喇| 潼关县| 黄山市| 共和县| 富源县| 姚安县| 榆树市| 安阳县| 阳江市| 会泽县| 乌拉特中旗| 益阳市| 西贡区| 东辽县| 涪陵区| 沈阳市| 醴陵市| 五寨县| 金川县| 天峨县| 灯塔市| 望都县| 彭州市| 武定县| 德令哈市| 临江市|