php生成静态页面的简单示例
发布新闻,实现新闻页面静态化,真静态
代码如下: 添加新闻 config.php 代码如下: define("HOST","localhost");
define("USER","justfan"); define("PWD","justfan"); define("DB","justfanDB"); define("PORT","3360"); ?> DB_class.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,$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 代码如下: include 'DB_class.php';
$db = DB::Instance(); $title=$_POST["title"]; $num = uniqid(); $sql="insert into news(title,content,path) values ('{$title}','{$content}','{$filename}')"; $fp=fopen("model.htm","r"); $dir = dirname($filename); $handle=fopen($filename,"w"); echo "查看刚才添加的新闻"; model.htm 代码如下:
{title}{content} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |