applicationcontext.xml php xml 메시지 보드 xml 데이터 저장의 간단한 예

WBOY
풀어 주다: 2016-07-29 08:40:35
원래의
869명이 탐색했습니다.

클래스 파일 : _class.xmldb.inc.php

코드 복사 코드는 다음과 같습니다.


class xmldb는 DOMDocument를 확장합니다.{
    var $xmldb;
    공용 함수 __construct($xmldbname){
        $this->xmldb=$xmldbname;
        if(!file_exists($this->xmldb)){
           $initxmldb = "";
            $this->loadXML($initxmldb);
            $this->save($this->xmldb);
        }else{
            $this->load($this->xmldb);
        }
    }
    공개 함수 insert_message($nickname,$message){
        $messagedom = $this->getElementsByTagName("Message");
        $subnode = $this->createElement("행");
        $nicknamenode = $this->createElement("닉네임");
        $nicknamenode -> AppendChild($this->createTextNode($nickname));
        $subnode -> AppendChild($닉네임노드);
        $contentnode = $this->createElement("콘텐츠");
        $contentnode -> AppendChild($this->createTextNode($message));
        $subnode -> AppendChild($contentnode);
        $timernode = $this->createElement("타이머");
        $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);
        $odom->length를 반환합니다.
    }
    공개 함수 get_message_list($start,$rowscount,$pagesize){
        $end = $rowscount > $페이지 크기 ? $start $pagesize : $rowscount;
        $k = 0;
        for($i = $start; $i < $end; $i ){
            $rowslist[$k]["Nickname"] = $this->getElementsByTagName("닉네임")-> ;item($i)->nodeValue;
            $rowslist[$k]["Content"] = $this->getElementsByTagName("Content")->item($i)->nodeValue;
            $rowslist[$k]["Timer"] = $this->getElementsByTagName("Timer")->item($i)->nodeValue;
            $k ;
        }
        $rowslist를 반환합니다.
    }
    공용 정적 함수 Splitpage($pageall,$page=1,$urled=null,$strpage = "page",$pageaverage = 10){
            $pageaverage -= 1;
            $page = intval($page >=1 ? $page : 1 );
            $page = $page > $ 페이지 올 ? $pageall : $페이지;
            $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)
            {
               $urled = ($k<>$strpage) ? $urled.$k.'='.urlencode($v).'&' : $urled;
            }
            if ($page>1){
               $mess ="首页 ";
               $mess .="上一页 ";
            }else{
                $mess ="首页 ";
               $mess .="上一页 ";
            }
            if($page > 9){
               $startpage = $page - 9;
            }
            $stoppage = $startpage 9 >= $pageall ? $pageall : $start페이지 9;
            for($i= $startpage; $i<= $stoppage ;$i )
            {
               if($i<= $pageall && !($page==$i))
$mess .= " ".$i."
               else
                   $mess .= "".$i." ";
            }
            if ($page < $pageall){
              $mess .=" 下一页";
               $mess .=" 尾页";
            }else{
                                                                                                  >}


호출 파일: 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']) :
$xmldb -> get_node_length("행");
$pagecount = ceil( $rowscount/$pagesize)
$start = ($page-1)*$pagesize > )*$pagesize;
$rowslist = $xmldb -> ; get_message_list($start,$rowscount,$pagesize)
?>
< HTML>

(".date(" Y-m-d H:i",$value["타이머"]). ")"
                                                  >                                                  입력 유형="텍스트" 이름=" nickname">

콘텐츠: