> php教程 > PHP源码 > 본문

新闻详细页静态化

PHP中文网
풀어 주다: 2016-05-25 16:59:19
원래의
1078명이 탐색했습니다.

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

<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>
로그인 후 복사


<?php
define("HOST","localhost");
define("USER","justfan");
define("PWD","justfan");
define("DB","justfanDB");
define("PORT","3360");
?>
로그인 후 복사


<?php
class DB
{
private $host = &#39;&#39;;
private $uname = &#39;&#39;;
private $pwd = &#39;&#39;;
private $port = &#39;&#39;;
private $db = &#39;&#39;;
 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 &#39;config.php&#39;;
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;
}


}
?>
로그인 후 복사


<?php
include &#39;DB_class.php&#39;;
$db = DB::Instance();

$title=$_POST["title"];
$content=$_POST["content"];

$num = uniqid();
$houzui=".html";
$filename=date(&#39;Ymd&#39;).&#39;/&#39;.$num.$houzui;

$sql="insert into news(title,content,path) values (&#39;{$title}&#39; , &#39;{$content}&#39; , &#39;{$filename}&#39;)";
$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=&#39;add.php&#39;>添加新闻</a>";
?>
로그인 후 복사


관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!