這篇文章給大家分享的是有關(guān)PHP如何實(shí)現(xiàn)適用于文件內(nèi)容操作的分頁類的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
成都創(chuàng)新互聯(lián)公司專注于臨武網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供臨武營(yíng)銷型網(wǎng)站建設(shè),臨武網(wǎng)站制作、臨武網(wǎng)頁設(shè)計(jì)、臨武網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造臨武網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供臨武網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。具體內(nèi)容如下
<?php class StrPage { private $current; //當(dāng)前頁 private $file; //操作文件 private $totalPage; //總的頁數(shù) private $url; //傳遞的參數(shù) private $pageLen; //每頁顯示的長(zhǎng)度 function __construct( $file,$len = 200 ){ $this->file = file_get_contents($file); $this->pageLen = $len; $this->current = isset($_GET['page'])?$_GET['page']:1; $this->totalPage = $this->getTotalPage(); $this->url = $this->getUrl(); } //獲取到這個(gè)文件總的長(zhǎng)度 private function getTotalPage(){ return ceil(strlen($this->file)/$this->pageLen); } //獲取當(dāng)前傳遞的參數(shù),保留參數(shù),page參數(shù)動(dòng)態(tài)變化 private function getUrl(){ $url =parse_url($_SERVER['REQUEST_URI']); parse_str($url['query'],$queryArr); unset($queryArr['page']); $queryStr = http_build_query($queryArr); return $url['path'].'?'.$queryStr.'&page='; } //首頁 private function first(){ if($this->current>1) return "<a href='".$this->url."1'>首頁</a>"; } //上一頁 private function pre(){ if( $this->current > 1 ) return "<a href='".$this->url.($this->current-1)."'>上一頁</a>"; } //下一頁 private function next(){ if( $this->current < $this->totalPage) return "<a href='".$this->url.($this->current+1)."'>下一頁</a>"; } //最后一頁 private function end(){ if( $this->current < $this->totalPage ) return "<a href='".$this->url.$this->totalPage."'>末頁</a>"; } public function pageList(){ $pageListStr = ''; for ($i=1;$i<=$this->totalPage;$i++){ if($i==$this->current){ $pageListStr.="<span style='font-size:20px;color:#f00'>".$i."</span> "; }else{ $pageListStr.="<a href='".$this->url.$i."'>".$i." </a>"; } } return $pageListStr; } public function pageStyle($style=1){ switch ($style){ case 1: return "共有".$this->totalPage."頁".$this->first().$this->pre().$this->pageList().$this->next().$this->end(); break; case 2; return $this->pageList(); break; } } public function getContents(){ $prePageLen = strlen($this->subStrs($this->current-1)); $currentPageLen = strlen($this->subStrs($this->current)); return substr($this->file, $prePageLen,$currentPageLen-$prePageLen); } public function subStrs($page){ $string = ''; $len= $page*$this->pageLen; for( $i=0; $i<$len; $i++ ){ if( ord(substr($this->file,$i,1))>0xa0 ){ $string .= substr($this->file,$i,3); $i = $i+2; }else{ $string .= substr($this->file, $i,1); } } return $string; } }
感謝各位的閱讀!關(guān)于“PHP如何實(shí)現(xiàn)適用于文件內(nèi)容操作的分頁類”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
網(wǎng)站標(biāo)題:PHP如何實(shí)現(xiàn)適用于文件內(nèi)容操作的分頁類-創(chuàng)新互聯(lián)
文章地址:http://vcdvsql.cn/article40/dsoseo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、網(wǎng)站收錄、網(wǎng)站改版、網(wǎng)頁設(shè)計(jì)公司、云服務(wù)器、全網(wǎng)營(yíng)銷推廣
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容