類別檔案 : _class.xmldb.inc.php
複製程式碼 程式碼如下:
class xmldb extends DOMDocument{
var $xmldb;
公用函數 __construct($xmldbname){
$this->xmldb=$xmldbname;
if(!file_exists($this->xmldb)){
$initxmldb = "留言 $this->loadXML($initxmldb);
$this->save($this->xmldb);
}其他{
$this->load($this->xmldb);
}
}
public function insert_message($nickname,$message){
$subnode = $this->createElement("Rows");
$nicknamenode = $this->createElement("暱稱");
$nicknamenode ->appendChild($this->createTextNode($nickname));
$子節點 ->追加子節點($nicknamenode);
$contentnode = $this->createElement("Content");
$contentnode ->appendChild($this->createTextNode($message));
$子節點 ->追加子節點($contentnode);
$timernode = $this->createElement("Timer");
$timernode ->appendChild($this->createTextNode(time()));
$子節點 ->追加子節點($timernode);
$messagedom->item(0)->appendChild($subnode);
$this->saveXML();
$this->save($this->xmldb);
}
函數 get_node_length($nodename){
$odom = $this->getElementsByTagName($nodename);
返回$odom->長度;
}
public function get_message_list($start,$rowscount,$pagesize){
$end = $rows🎜> $end = $rowsscount >; $pagesize?
$k = 0;
for($i = $start; $i $rowslist[$k]["mname"] =$"em"m ($i)->節點值;
$rowslist[$k]["Content"] = $this->getElementsByTagName("Content")->item($i)->nodeValue;
$rowslist[$k]["Timer"] = $this->getElementsByTagName("Timer")->item($i)->nodeValue;
$k++;
}
}
公共靜態函數 splitpage($pageall,$page=1,$urled=null,$strpage = "page",$pageaverage = 10){
$page = intval($page >=1 ? $page : 1 );
$page = $page> $pageall ? $pageall : $page;
$startpage = $page - $pageaverage > 0 ? $page - ceil(($pageaverage / 2)):1;
$startpage = ($page + ceil($pageaverage/2) > $pageall)?$pageall-$pageaverage:$startpage;
$startpage = $startpage> 0 ? $起始頁:1;
$stoppage = $startpage+$pageaverage >$pageall?$pageall:$startpage+$pageaverage;
if(empty($urlfile)){ $urlfile=$_SERVER["PHP_SELF"]; }
if(!strrpos($urlfile,'?')) $urled .= '?';
foreach($_GET as $k => $v)
>$strpage) ? $urled.$k.'='.urlencode($v).'&' : $urled;
}
if ($page>1){ 首頁 ";
$mess .="上一頁";
} 否則{
$mess ="首頁 $mess ="首頁 ";
$mess .="上一頁 ";
}
if($pagepage >
}
$stoppage = $startpage + 9 >= $pageall ? $pageall : $startpage + 9;
for($i= $startpage; $i $i $mess .= " ". $i。 ";
}
if ($page all){ ".$urled.$strpage."=".($page+1)。 "" href="".$urled.$strpage."=".($page+1)."">下一頁";
$mess .="尾頁";
}else{
$mess .=" 下一頁";
}
return $mess;
}
}
? >
複製程式碼 程式碼如下:
程式碼如下: php
require("_class.xmldb.inc.php");
$xmldb = new xmldb("./my_xmldb.xml");
if(isset($_POST["btnform1"]) ){
$xmldb -> insert_message($_POST["nickname"],$_POST["content"]);
}
$page !empty($ _GET['page']) ? intval($_GET['page']) : 1;
$rowscount = $xmldb -> get_node_length("Rows"); $. pagesize);
$start = ($page-1)*$pagesize > $rowscount ? $rowscount : ($page-1)*$pagesize;
$rowslist =$ $rowscount,$pagesize);
?>