- <?php
- /*
- *長文章分頁類
- *author tdweb@GGT
- *date 2008-8-4
- *$content 要拆分的文章內容
- */
- Class cutContent{
- public $content;
- public $limit;
- public $length;
- public $pageCount;
- public $nowPage;
- public $contentLeft;
- public $contentRight;
- public $array_content;
- public $page_array_content;
- public $page_tag='#p#';
- function cutContent() {
- $this->limit=270;
- $this->nowPage = $_REQUEST['pagec']?$_REQUEST['pagec']:1;
- }
- /*
- *需要用到的字符串截取方法
- */
- function msubstr($str,$start,$len)
- {
- $strlen = $start +$len;
- for($i=0;$i<$strlen;$i++)
- {
- if(ord(substr($str,$i,1))>0xa0)
- {
- $temstr .= substr($str,$i,2);
- $i++;
- }
- else
- {
- $temstr .=substr($str,$i,1);
- }
- }
- return $temstr;
- }
- /*
- *獲取當前頁內容
- */
- function getPerContent(){
- if (strpos($this->content,$this->page_tag) > -1){
- $arr_all_content=explode($this->page_tag,$this->content);
- $this->pageCount=count($arr_all_content);
- if($this->pageCount<$this->nowPage) $this->nowPage = 1;
- $this->contentLeft=$arr_all_content[$this->nowPage-1];
- $this->contentRight=$arr_all_content[$this->nowPage+1];
- $this->array_content=$arr_all_content[$this->nowPage-1];
- return $this->array_content;
- }else{
- $this->length=strlen($this->content);
- $this->pageCount=ceil($this->length/$this->limit);
- if($this->pageCount<$this->nowPage) $this->nowPage = 1;
- $this->contentLeft = $this->msubstr($this->content,0,($this->nowPage-1)*$this->limit);
- $this->contentRight= $this->msubstr($this->content,0,$this->nowPage*$this->limit);
- $this->array_content = substr($this->contentRight,strlen($this->contentLeft),strlen($this->contentRight)-strlen($this->contentLeft));
- $this->page_array_content=strlen($this->array_content);
- return $this->array_content;
- }
- }
- /*
- *獲取分頁列表
- */
- function getPages(){
- $result="";
- if (1==$this->getAllCount()){
- $result='<div id="footer_nopage"> <a class="prev" style="background-color:#000;filter:Alpha(Opacity=60);"></a> <a class="next" style="background-color:#000;filter:Alpha(Opacity=60);"></a> <a class="home" href="index.php" style="background-color:#000;filter:Alpha(Opacity=60);"></a> </div>';
- }else{
- $result = '<div id="footer">';
- if ($this->nowPage>1){
- $result .= '<a class="prev" style="background-color:#000;filter:Alpha(Opacity=60);" href="javascript:goPage2(' . ($this->nowPage-1) . ',/'' . $base_url .'/')"></a>';
- }else{
- $result .= '<a class="prev" style="background-color:#000;filter:Alpha(Opacity=60);"></a>';
- }
- if ($this->nowPage==$this->pageCount){
- $result .= '<a class="next" style="background-color:#000;filter:Alpha(Opacity=60);"></a>';
- }else{
- $result .= '<a class="next" style="background-color:#000;filter:Alpha(Opacity=60);" href="javascript:goPage2(' . ($this->nowPage + 1) . ',/'' . $base_url . '/')"></a>';
- }
- $result .= '<a class="home" style="background-color:#000;filter:Alpha(Opacity=60);" href="/index.php"></a> ';
- $result .= ' </DIV>';
- }
- return $result;
- }
- /*
- *獲取當前頁字符數
- */
- function getNowCount(){
- return strlen($this->getPerContent());
- }
- /*
- *獲取當前頁碼
- */
- function getNowPage(){
- return $this->nowPage;
- }
- /*
- *獲取頁碼總數
- */
- function getAllCount(){
- if (strpos($this->content,$this->page_tag) > -1){
- $arr_all_content=explode($this->page_tag,$this->content);
- $this->pageCount=count($arr_all_content);
- return $this->pageCount;
- }else{
- $this->length=strlen($this->content);
- $this->pageCount=ceil($this->length/$this->limit);
- return $this->pageCount;
- }
- }
- /*
- *獲取當前頁-總頁數的字符串
- */
- function getOne2All(){
- $return='';
- $return = "(";
- $return .= $this->getNowPage();
- $return .= "/";
- $return .= $this->getAllCount();
- $return .= ")";
- return $return;
- }
- }
- ?>
你要用的話,分頁方式還需要再改一下。
會首先搜索分頁標籤,$page_tag,如果存在分頁標籤,則按照分頁標籤進行分頁。
如果不存在,則按照$page_limit進行分頁。