静态网页制作代码php,php生成静态页面的简单示例

发布新闻,实现新闻页面静态化,真静态

add.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,$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

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 "查看刚才添加的新闻";

echo "添加新闻";

?>

model.htm

{title}

{title}

{content}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值