您好,登錄后才能下訂單哦!
本篇文章為大家展示了php中怎么生成靜態頁面,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
add.php
<html> <head>添加新聞</head> <body> <form method="post" action="doadd.php"> 新聞標題:<input type="text" name="title" size="100"><br> 新聞內容:<textarea name="content" cols="100" rows="25"></textarea><br> <input type="submit" name="提交"> </form> </body> </html>
config.php
<?php define("HOST", "localhost"); define("USER", "justfan"); define("PWD", "justfan"); define("DB", "justfanDB"); define("PORT", "3360"); ?>
DB_class.php
<?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
<?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
<!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="//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"> <h2>{title}</h2> <p>{content}</p> </div> </div> </body></html>
上述內容就是php中怎么生成靜態頁面,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。