




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
PHP长文章分页的使用例子文章分页用到比较多同时使用过cms的朋友也碰到过都具备了文章分页功能了,下面我们自己来看一个关于文章分页的例子,具体的操作步骤如下所示,希望文章能够帮助到各位朋友.content.txt:这个文件里面放的是内容了,如果你是与mysql数据库结合的话只要把把这一句换成你的数据库的内容即可.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">网站模板</a></li><li><ahref="http:///js">网页特效</a></li><li><ahref="http:///php">PHP</a></li><li><ahref="http:///site">精选网址</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代码,若字符串中有手动分页符{nextpage}则优先按手动分页符进行分页$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;//被切分的内容private$pagearr;//被切分文字的数组格式private$sum_word;//总字数(UTF-8格式的中文字符也包括)private$sum_page;//总页数private$page_word;//一页多少字private$cut_tag;//自动分页符private$cut_custom;//手动分页符private$ipage;//当前切分的页数,第几页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;}//统计总字数functionget_page_word(){$this->sum_word=$this->strlen_utf8($this->pagestr);return$this->sum_word;}/*统计UTF-8编码的字符长度*一个中文,一个英文都为一个字*/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;}//设置自动分页符号functionset_cut_tag($tag_arr=array()){$this->cut_tag=$tag_arr;}//设置手动分页符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得到的字符总数$i=0;if($str_len_word<=$this->page_word){//如果总字数小于一页显示字数$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个文字cutStr为func.global中的函数foreach($this->cut_tagas$v){$cut_start=strrpos($str_first,$v);//逆向查找第一个分页符的位置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){//如果超过总字数$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个字后的page_word个字符$cut_tmp=strrpos($str_tmp,$v);//找出从第cut_start个字之后,page_word个字之间,逆向查找第一个分页符的位置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);//总页数$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等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年硬质沥青项目可行性研究报告
- 打桩租赁合同范本
- 抖音未成年人退款协议书
- 年产500万套吸塑包装生产线可行性研究报告申请备案
- 2025年GPS射频芯片项目可行性研究报告
- 2025至2030年金蓝宝耳环项目投资价值分析报告
- 2025至2030年鞋业专用HRP软件项目投资价值分析报告
- 2025年挤出蜂窝陶瓷材料合作协议书
- 射线孔砖行业市场发展及发展趋势与投资战略研究报告
- 9《正确认识广告》(教学设计)-2024-2025学年统编版道德与法治四年级上册
- 2025年山东化工职业学院高职单招职业适应性测试近5年常考版参考题库含答案解析
- 2025年全国幼儿园教师资格证考试教育理论知识押题试题库及答案(共九套)
- 2024年郑州电力高等专科学校高职单招职业适应性测试历年参考题库含答案解析
- 产品试产流程
- 舞台机械基础知识培训
- 人教版数学八年级下册 第16章 二次根式 单元测试(含答案)
- 中学班主任培训内容
- DB51T 1511-2022建设项目对自然保护区自然资源、自然生态
- 2024年湘教版初中地理一轮复习专题三 天气与气候
- 四级人工智能训练师(中级)职业技能等级认定考试题及答案
- 运用HFMEA品管工具优化临床安全输血流程医院品质管理获奖案例(护理部联合临床输血科信息处)
评论
0/150
提交评论