PHP長文章分頁的使用例子_第1頁
PHP長文章分頁的使用例子_第2頁
PHP長文章分頁的使用例子_第3頁
PHP長文章分頁的使用例子_第4頁
PHP長文章分頁的使用例子_第5頁
已閱讀5頁,還剩1頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

PHP長文章分頁的使用例子文章分頁用到比較多同時(shí)使用過cms的朋友也碰到過都具備了文章分頁功能了,下面我們自己來看一個(gè)關(guān)于文章分頁的例子,具體的操作步驟如下所示,希望文章能夠幫助到各位朋友.content.txt:這個(gè)文件里面放的是內(nèi)容了,如果你是與mysql數(shù)據(jù)庫結(jié)合的話只要把把這一句換成你的數(shù)據(jù)庫的內(nèi)容即可.index.php文件:<linkrel="stylesheet"type="text/css"href="http:///jquery/css/common.css"/><styletype="text/css">.demo{width:80%;margin:50pxauto10pxauto;padding:10px;}.demop{line-height:30px;text-indent:2em}.demoh3{font-size:24px;text-align:center;padding:10px}@media(max-width:480px){.demo{width:360px;margin:50pxauto10pxauto;padding:10px;}.demoimg{width:90%}.demoh3{font-size:1.5em;line-height:1.9em}}.pages{text-align:center;border-top:1pxsolid#d3d3d3;margin-top:10px;padding-top:10px}.pagesa{display:inline-block;margin:4px;padding:4px8px;background:#f9f9f9;border:1pxsolid#d9d9d9}.pagesa.cur{cursor:default;background:#d3d3d3;color:#434343}.pagesa.cur:hover{text-decoration:none}</style><divclass="head"><divclass="head_innerclearfix"><ulid="nav"><li><ahref="http://">首頁</a></li><li><ahref="http:///templates">網(wǎng)站模板</a></li><li><ahref="http:///js">網(wǎng)頁特效</a></li><li><ahref="http:///php">PHP</a></li><li><ahref="http:///site">精選網(wǎng)址</a></li></ul><aclass="logo"href="http://"><imgsrc="http:///Public/images/logo.jpg"alt="素材火logo"/></a></div></div><divclass="container"><divclass="demo"><h2class="title"><ahref="http:///js/639.html">教程:PHP長文章分頁教程與演示</a></h2><h3>未來10年千萬人將沒有工作?</h3><?phpinclude('page.class.php');//自定義的長文章字符串,可以包含html代碼,若字符串中有手動(dòng)分頁符{nextpage}則優(yōu)先按手動(dòng)分頁符進(jìn)行分頁$content=file_get_contents('content.txt');$ipage=isset($_GET["ipage"])?intval($_GET["ipage"]):1;$CP=newcutpage($content);$page=$CP->cut_str();echo$page[$i1];echo'<divclass="pages">'.$CP->pagenav().'</div>';?></div></div>長文章分頁類page.class.php:<?php/**長文章分頁類*/classcutpage{private$pagestr;//被切分的內(nèi)容private$pagearr;//被切分文字的數(shù)組格式private$sum_word;//總字?jǐn)?shù)(UTF-8格式的中文字符也包括)private$sum_page;//總頁數(shù)private$page_word;//一頁多少字private$cut_tag;//自動(dòng)分頁符private$cut_custom;//手動(dòng)分頁符private$ipage;//當(dāng)前切分的頁數(shù),第幾頁private$url;function__construct($pagestr,$page_word=1000){$this->page_word=$page_word;$this->cut_tag=array("</table>","</div>","</p>","<br/>","”。","。",".","!","……","?",",");$this->cut_custom="{nextpage}";$tmp_page=isset($_GET["ipage"])?intval($_GET["ipage"]):1;$this->ipage=$tmp_page>1?$tmp_page:1;$this->pagestr=$pagestr;}//統(tǒng)計(jì)總字?jǐn)?shù)functionget_page_word(){$this->sum_word=$this->strlen_utf8($this->pagestr);return$this->sum_word;}/*統(tǒng)計(jì)UTF-8編碼的字符長度*一個(gè)中文,一個(gè)英文都為一個(gè)字*/functionstrlen_utf8($str){$i=0;$count=0;$len=strlen($str);while($i<$len){$chr=ord($str[$i]);$count++;$i++;if($i>=$len)break;if($chr&0x80){$chr<<=1;while($chr&0x80){$i++;$chr<<=1;}}}return$count;}//設(shè)置自動(dòng)分頁符號(hào)functionset_cut_tag($tag_arr=array()){$this->cut_tag=$tag_arr;}//設(shè)置手動(dòng)分頁符functionset_cut_custom($cut_str){$this->cut_custom=$cut_str;}functionshow_cpage($ipage=0){$this->cut_r();$ipage=$ipage?$ipage:$this->ipage;return$this->pagearr[$ipage];}functioncut_str(){$str_len_word=strlen($this->pagestr);//獲取使用strlen得到的字符總數(shù)$i=0;if($str_len_word<=$this->page_word){//如果總字?jǐn)?shù)小于一頁顯示字?jǐn)?shù)$page_arr[$i]=$this->pagestr;}else{if(strpos($this->pagestr,$this->cut_custom)){$page_arr=explode($this->cut_custom,$this->pagestr);}else{$str_first=substr($this->pagestr,0,$this->page_word);//0_word個(gè)文字cutStr為func.global中的函數(shù)foreach($this->cut_tagas$v){$cut_start=strrpos($str_first,$v);//逆向查找第一個(gè)分頁符的位置if($cut_start){$page_arr[$i++]=substr($this->pagestr,0,$cut_start).$v;$cut_start=$cut_start+strlen($v);break;}}if(($cut_start+$this->page_word)>=$str_len_word){//如果超過總字?jǐn)?shù)$page_arr[$i++]=substr($this->pagestr,$cut_start,$this->page_word);}else{while(($cut_start+$this->page_word)<$str_len_word){foreach($this->cut_tagas$v){$str_tmp=substr($this->pagestr,$cut_start,$this->page_word);//取第cut_start個(gè)字后的page_word個(gè)字符$cut_tmp=strrpos($str_tmp,$v);//找出從第cut_start個(gè)字之后,page_word個(gè)字之間,逆向查找第一個(gè)分頁符的位置if($cut_tmp){$page_arr[$i++]=substr($str_tmp,0,$cut_tmp).$v;$cut_start=$cut_start+$cut_tmp+strlen($v);break;}}}if(($cut_start+$this->page_word)>$str_len_word){$page_arr[$i++]=substr($this->pagestr,$cut_start,$this->page_word);}}}}$this->sum_page=count($page_arr);//總頁數(shù)$this->pagearr=$page_arr;return$page_arr;}//顯示上一條,下一條functionpagenav(){$this->set_url();$str='';//$str.=$this->ipage.'/'.$this->sum_page;for($i=1;$i<=$this->sum_page;$i++){if($i==$this->ipage){$str.="<ahref='#'class='cur'>".$i."</a>";}else{$str.="<ahref='".$this->url.$i."'>".$i."</a>";}}return$str;}functionshow_prv_next2(){$this->set_url();$str='';if($this->sum_page>1and$this->ipage>1){$str.="<ahref='".$this->url.($this->i1)."'>上一頁</a>";}if($this->sum_page>1and$this->ipage<$this->sum_page){$str.="<ahref='".$this->url.($this->ipage+1)."'>下一頁</a>";}return$str;}functionshow_page_select(){if($this->sum_page>1){$str="<selectonchange='location.href=this.options[this.selectedIndex].value'>";for($i=1;$i<=$this->sum_page;$i++){$str.="<optionvalue='".$this->url.$i."'".(($this->ipage)==$i?"selected='selected'":"").">第".$i."頁</option>";}$str.="</se

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論