最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php生成靜態(tài)頁(yè)面的簡(jiǎn)單示例

 更新時(shí)間:2014年04月17日 10:08:13   作者:  
這篇文章主要介紹了php生成靜態(tài)頁(yè)面的簡(jiǎn)單示例,需要的朋友可以參考下

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


add.php

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

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

 <body>
   <form method="post" action="doadd.php">
     新聞標(biāo)題:<input type="text" name="title" size="100"><br>
     新聞內(nèi)容:<textarea name="content" cols="100" rows="25"></textarea><br>
     <input type="submit" name="提交">
   </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').'/'.$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 rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
 <link rel="stylesheet" href="../bootstrap/css/common.css">
 <title>{title}</title>
</head>
  <body>

    <div class="container">
      <div class="jumbotron">
        <h1>{title}</h1>
        <p>{content}</p>
      </div>
    </div>
  </body>
</html>

相關(guān)文章

最新評(píng)論

黄龙县| 蓬莱市| 子洲县| 仁布县| 荣成市| 雷州市| 尼木县| 孟州市| 渝北区| 吉安市| 栖霞市| 泰州市| 永丰县| 内黄县| 深州市| 仪征市| 阿拉善右旗| 四平市| 玉环县| 林芝县| 疏勒县| 隆化县| 温宿县| 莎车县| 永善县| 二连浩特市| 赤壁市| 宁德市| 凉城县| 定襄县| 台江县| 东光县| 绩溪县| 玉树县| 石城县| 察雅县| 台前县| 曲阜市| 长乐市| 睢宁县| 格尔木市|