- <?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进行分页。