无为清净楼资源网 Design By www.qnjia.com
类文件 : _class.xmldb.inc.php
复制代码 代码如下:
<?php
class xmldb extends DOMDocument{
var $xmldb;
public function __construct($xmldbname){
$this->xmldb=$xmldbname;
if(!file_exists($this->xmldb)){
$initxmldb = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Message></Message>";
$this->loadXML($initxmldb);
$this->save($this->xmldb);
}else{
$this->load($this->xmldb);
}
}
public function insert_message($nickname,$message){
$messagedom = $this->getElementsByTagName("Message");
$subnode = $this->createElement("Rows");
$nicknamenode = $this->createElement("Nickname");
$nicknamenode -> appendChild($this->createTextNode($nickname));
$subnode -> appendChild($nicknamenode);
$contentnode = $this->createElement("Content");
$contentnode -> appendChild($this->createTextNode($message));
$subnode -> appendChild($contentnode);
$timernode = $this->createElement("Timer");
$timernode -> appendChild($this->createTextNode(time()));
$subnode -> appendChild($timernode);
$messagedom->item(0)->appendChild($subnode);
$this->saveXML();
$this->save($this->xmldb);
}
function get_node_length($nodename){
$odom = $this->getElementsByTagName($nodename);
return $odom->length;
}
public function get_message_list($start,$rowscount,$pagesize){
$end = $rowscount > $pagesize ? $start+$pagesize : $rowscount;
$k = 0;
for($i = $start; $i < $end; $i++){
$rowslist[$k]["Nickname"] = $this->getElementsByTagName("Nickname")->item($i)->nodeValue;
$rowslist[$k]["Content"] = $this->getElementsByTagName("Content")->item($i)->nodeValue;
$rowslist[$k]["Timer"] = $this->getElementsByTagName("Timer")->item($i)->nodeValue;
$k++;
}
return $rowslist;
}
public static function splitpage($pageall,$page=1,$urled=null,$strpage = "page",$pageaverage = 10){
$pageaverage -= 1;
$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 ? $startpage : 1;
$stoppage = $startpage+$pageaverage >$pageall?$pageall:$startpage+$pageaverage;
if(empty($urlfile)){ $urlfile=$_SERVER["PHP_SELF"]; }
if(!strrpos($urlfile,'?')) $urled .= '?';
foreach($_GET as $k => $v)
{
$urled = ($k<>$strpage) ? $urled.$k.'='.urlencode($v).'&' : $urled;
}
if ($page>1){
$mess ="<a href="".$urled.$strpage."=1" href="".$urled.$strpage."=1">首页</a> ";
$mess .="<a href="".$urled.$strpage."=".($page-1)."" href="".$urled.$strpage."=".($page-1)."">上一页 </a>";
}else{
$mess ="首页 ";
$mess .="上一页 ";
}
if($page > 9){
$startpage = $page - 9;
}
$stoppage = $startpage + 9 >= $pageall ? $pageall : $startpage + 9;
for($i= $startpage; $i<= $stoppage ;$i++)
{
if($i<= $pageall && !($page==$i))
$mess .= "<a href="".$urled.$strpage."=".$i."" href="".$urled.$strpage."=".$i."">".$i."</a> ";
else
$mess .= "".$i." ";
}
if ($page < $pageall){
$mess .=" <a href="".$urled.$strpage."=".($page+1)."" href="".$urled.$strpage."=".($page+1)."">下一页</a>";
$mess .=" <a href="".$urled.$strpage."=".$pageall."" href="".$urled.$strpage."=".$pageall."">尾页</a>";
}else{
$mess .=" 下一页";
$mess .=" 尾页";
}
return $mess;
}
}
?>
调用文件 : index.php
复制代码 代码如下:
<?php
require("_class.xmldb.inc.php");
$xmldb = new xmldb("./my_xmldb.xml");
if(isset($_POST["btnform1"])){
$xmldb -> insert_message($_POST["nickname"],$_POST["content"]);
}
$pagesize = 3;
$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
$rowscount = $xmldb -> get_node_length("Rows");
$pagecount = ceil($rowscount/$pagesize);
$start = ($page-1)*$pagesize > $rowscount ? $rowscount : ($page-1)*$pagesize;
$rowslist = $xmldb -> get_message_list($start,$rowscount,$pagesize);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE> New Document </TITLE>
<style type='text/css'><!--
#messagelist ul li{ float:left;list-style-type:none; }
--></style><style type='text/css' bogus="1"> #messagelist ul li{ float:left;list-style-type:none; }
</style>
</HEAD>
<BODY>
<div id="messagelist">
<?php
if(!empty($rowslist))
{
foreach($rowslist as $key => $value)
{
echo "<ul><li>".$value["Nickname"]." <span>(".date("Y-m-d H:i",$value["Timer"]).")</span></li>";
echo "<li>".$value["Content"]."</li></ul><br>";
}
}
?>
<div><?=$xmldb -> splitpage($pagecount,$page,'','page',$pagesize)?></div>
</div>
<div>
<form action="" method="post" name="form1">
昵称:<input type="text" name="nickname"><br>
内容:<textarea name="content">
php操作xml的简单留言板,带分页,仅供参考
复制代码 代码如下:
<?php
class xmldb extends DOMDocument{
var $xmldb;
public function __construct($xmldbname){
$this->xmldb=$xmldbname;
if(!file_exists($this->xmldb)){
$initxmldb = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Message></Message>";
$this->loadXML($initxmldb);
$this->save($this->xmldb);
}else{
$this->load($this->xmldb);
}
}
public function insert_message($nickname,$message){
$messagedom = $this->getElementsByTagName("Message");
$subnode = $this->createElement("Rows");
$nicknamenode = $this->createElement("Nickname");
$nicknamenode -> appendChild($this->createTextNode($nickname));
$subnode -> appendChild($nicknamenode);
$contentnode = $this->createElement("Content");
$contentnode -> appendChild($this->createTextNode($message));
$subnode -> appendChild($contentnode);
$timernode = $this->createElement("Timer");
$timernode -> appendChild($this->createTextNode(time()));
$subnode -> appendChild($timernode);
$messagedom->item(0)->appendChild($subnode);
$this->saveXML();
$this->save($this->xmldb);
}
function get_node_length($nodename){
$odom = $this->getElementsByTagName($nodename);
return $odom->length;
}
public function get_message_list($start,$rowscount,$pagesize){
$end = $rowscount > $pagesize ? $start+$pagesize : $rowscount;
$k = 0;
for($i = $start; $i < $end; $i++){
$rowslist[$k]["Nickname"] = $this->getElementsByTagName("Nickname")->item($i)->nodeValue;
$rowslist[$k]["Content"] = $this->getElementsByTagName("Content")->item($i)->nodeValue;
$rowslist[$k]["Timer"] = $this->getElementsByTagName("Timer")->item($i)->nodeValue;
$k++;
}
return $rowslist;
}
public static function splitpage($pageall,$page=1,$urled=null,$strpage = "page",$pageaverage = 10){
$pageaverage -= 1;
$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 ? $startpage : 1;
$stoppage = $startpage+$pageaverage >$pageall?$pageall:$startpage+$pageaverage;
if(empty($urlfile)){ $urlfile=$_SERVER["PHP_SELF"]; }
if(!strrpos($urlfile,'?')) $urled .= '?';
foreach($_GET as $k => $v)
{
$urled = ($k<>$strpage) ? $urled.$k.'='.urlencode($v).'&' : $urled;
}
if ($page>1){
$mess ="<a href="".$urled.$strpage."=1" href="".$urled.$strpage."=1">首页</a> ";
$mess .="<a href="".$urled.$strpage."=".($page-1)."" href="".$urled.$strpage."=".($page-1)."">上一页 </a>";
}else{
$mess ="首页 ";
$mess .="上一页 ";
}
if($page > 9){
$startpage = $page - 9;
}
$stoppage = $startpage + 9 >= $pageall ? $pageall : $startpage + 9;
for($i= $startpage; $i<= $stoppage ;$i++)
{
if($i<= $pageall && !($page==$i))
$mess .= "<a href="".$urled.$strpage."=".$i."" href="".$urled.$strpage."=".$i."">".$i."</a> ";
else
$mess .= "".$i." ";
}
if ($page < $pageall){
$mess .=" <a href="".$urled.$strpage."=".($page+1)."" href="".$urled.$strpage."=".($page+1)."">下一页</a>";
$mess .=" <a href="".$urled.$strpage."=".$pageall."" href="".$urled.$strpage."=".$pageall."">尾页</a>";
}else{
$mess .=" 下一页";
$mess .=" 尾页";
}
return $mess;
}
}
?>
调用文件 : index.php
复制代码 代码如下:
<?php
require("_class.xmldb.inc.php");
$xmldb = new xmldb("./my_xmldb.xml");
if(isset($_POST["btnform1"])){
$xmldb -> insert_message($_POST["nickname"],$_POST["content"]);
}
$pagesize = 3;
$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
$rowscount = $xmldb -> get_node_length("Rows");
$pagecount = ceil($rowscount/$pagesize);
$start = ($page-1)*$pagesize > $rowscount ? $rowscount : ($page-1)*$pagesize;
$rowslist = $xmldb -> get_message_list($start,$rowscount,$pagesize);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE> New Document </TITLE>
<style type='text/css'><!--
#messagelist ul li{ float:left;list-style-type:none; }
--></style><style type='text/css' bogus="1"> #messagelist ul li{ float:left;list-style-type:none; }
</style>
</HEAD>
<BODY>
<div id="messagelist">
<?php
if(!empty($rowslist))
{
foreach($rowslist as $key => $value)
{
echo "<ul><li>".$value["Nickname"]." <span>(".date("Y-m-d H:i",$value["Timer"]).")</span></li>";
echo "<li>".$value["Content"]."</li></ul><br>";
}
}
?>
<div><?=$xmldb -> splitpage($pagecount,$page,'','page',$pagesize)?></div>
</div>
<div>
<form action="" method="post" name="form1">
昵称:<input type="text" name="nickname"><br>
内容:<textarea name="content">
php操作xml的简单留言板,带分页,仅供参考
标签:
php,xml,留言板
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月15日
2024年11月15日
- 黄乙玲1988-无稳定的爱心肝乱糟糟[日本东芝1M版][WAV+CUE]
- 群星《我们的歌第六季 第3期》[320K/MP3][70.68MB]
- 群星《我们的歌第六季 第3期》[FLAC/分轨][369.48MB]
- 群星《燃!沙排少女 影视原声带》[320K/MP3][175.61MB]
- 乱斗海盗瞎6胜卡组推荐一览 深暗领域乱斗海盗瞎卡组分享
- 炉石传说乱斗6胜卡组分享一览 深暗领域乱斗6胜卡组代码推荐
- 炉石传说乱斗本周卡组合集 乱斗模式卡组最新推荐
- 佟妍.2015-七窍玲珑心【万马旦】【WAV+CUE】
- 叶振棠陈晓慧.1986-龙的心·俘虏你(2006复黑限量版)【永恒】【WAV+CUE】
- 陈慧琳.1998-爱我不爱(国)【福茂】【WAV+CUE】
- 咪咕快游豪礼放送,百元京东卡、海量欢乐豆就在咪咕咪粉节!
- 双11百吋大屏焕新“热”,海信AI画质电视成最大赢家
- 海信电视E8N Ultra:真正的百吋,不止是大!
- 曾庆瑜1990-曾庆瑜历年精选[派森][WAV+CUE]
- 叶玉卿1999-深情之选[飞图][WAV+CUE]