php生成静态页面的简单示例
php  /  管理员 发布于 8年前   182
发布新闻,实现新闻页面静态化,真静态 config.php DB_class.php private function __construct($host , $uname , $pwd , $port , $db) mysql_connect($host,$uname,$pwd); public static function Instance() public function query($sql) doadd.php $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 {content} 122 在 123 在 原梓番博客 在 博主 在 1111 在
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号
add.php
添加新闻
define("HOST", "localhost");
define("USER", "justfan");
define("PWD", "justfan");
define("DB", "justfanDB");
define("PORT", "3360");
?>
class DB
{
private $host = '';
private $uname = '';
private $pwd = '';
private $port = '';
private $db = '';
public static $instance = null;
{
$this->host = $host;
$this->uname = $uname;
$this->port = $port;
$this->pwd = $pwd;
$this->db = $db;
mysql_select_db($this->db);
}
{
if(Db::$instance==null){
include 'config.php';
return Db::$instance = new DB(HOST, USER, PWD, PORT, DB);
}
else
return Db::$instance;
}
{
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;
}
}
?>
include 'DB_class.php';
$db = DB::Instance();
$content=$_POST["content"];
$houzui=".html";
$filename=date('Ymd').'/'.$num.$houzui;
$query = $db->query($sql);
$str=fread($fp,filesize("model.htm"));
$str=str_replace("{title}",$title,$str);
$str=str_replace("{content}",$content,$str);
fclose($fp);
if(!is_dir($dir)){
mkdir($dir);
}
fwrite($handle,$str);
fclose($handle);
echo "添加新闻";
?>
{title}
您可能感兴趣的文章:
上一条:
php实现的漂亮分页方法
下一条:
php文件服务实现虚拟挂载其他目录示例
