php 文件分页类
/** * 文件分页类 */ class FilePage { private $current; //当前页 private $file; //文件内容 private $totalPage; //总的页数 private $url; //传递的参数 private $pageLen; //每页显示的长度 /** * [__construct description] 构造方法 数据初始化 * @author lianggc 2016-06-28 * @param string $file_path [description] 文件路径 * @param integer $len [description] 每页显示多少数据 */ function __construct( $file_path='',$len = 200 ){ if(!file_exists($file_path)){ die("$file_path not exists"); } $this->file = file_get_contents($file_path); $this->pageLen = $len; $this->current = isset($_GET['page'])?$_GET['page']:1; $this->totalPage = $this->getTotalPage(); $this->pageOverflow(); $this->url = $this->getUrl(); } /** * [pageOverflow description] 页数溢出 * @author lianggc 2016-06-28 * @return [type] [description] */ private function pageOverflow(){ if($this->current>$this->totalPage){ //当页大于最大页 $this->current=$this->totalPage; } if($this->currentcurrent=1; } } /** * [getTotalPage description] 计算最大页数 * @author lianggc 2016-06-28 * @return [type] [description] */ private function getTotalPage(){ return ceil(strlen($this->file)/$this->pageLen); } /** * [getUrl description] url拼接 * @author lianggc 2016-06-28 * @return [type] [description] */ private function getUrl(){ $url =parse_url($_SERVER['REQUEST_URI']); parse_str(isset($url['query'])?$url['query']:'',$queryArr); unset($queryArr['page']); $query_str = http_build_query($queryArr); if(empty($query_str)){ return $url['path'].'?page='; }else{ return $url['path'].'?'.$query_str.'&page='; } } //首页 private function first(){ if($this->current>1) return "<a href="'%22.%24this-">url."1'>首页</a>"; } //上一页 private function pre(){ if( $this->current > 1 ) return "<a href="'%22.%24this-">url.($this->current-1)."'>上一页</a>"; } //下一页 private function next(){ if( $this->current totalPage) return "<a href="'%22.%24this-">url.($this->current+1)."'>下一页</a>"; } //最后一页 private function end(){ if( $this->current totalPage ) return "<a href="'%22.%24this-">url.$this->totalPage."'>末页</a>"; } /** * [pageList description] 拼接 分页数 1 2 3 4 5 6 * @author lianggc 2016-06-28 * @return [type] [description] */ public function pageList(){ $pageListStr = ''; for ($i=1;$itotalPage;$i++){ if($i==$this->current){ $pageListStr.="<span style="'font-size:20px;color:#f00'">".$i."</span> "; }else{ $pageListStr.="<a href="'%22.%24this-">url.$i."'>".$i." </a>"; } } return $pageListStr; } /** * [pageStyle description] 分页显示格式 * @author lianggc 2016-06-28 * @param integer $style [description] 分页格式 * @return [type] [description] */ 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; } } /** * [getContents description] 获取每页内容。 暂不支持中文 * @author lianggc 2016-06-28 * @return [type] [description] */ public function getContents(){ $prePageLen = strlen($this->subStrs($this->current-1)); $currentPageLen = strlen($this->subStrs($this->current)); return substr($this->file, $prePageLen,$currentPageLen-$prePageLen); } /** * [subStrs description] 文件内容截取 * @author lianggc 2016-06-28 * @param [type] $page [description] 页数 * @return [type] [description] */ public function subStrs($page){ $string = ''; $len= $page*$this->pageLen; for( $i=0; $ifile,$i,1))>0xa0 ){ $string .= substr($this->file,$i,3); $i = $i+2; }else{ $string .= substr($this->file, $i,1); } } return $string; } }
使用如下
<span style="font-family: Arial, Helvetica, sans-serif;">$file_obj=new FilePage('../test.txt',1);</span>
echo $file_obj->getContents(); echo "<br>"; echo $file_obj->pageStyle();
以上就介绍了 php 文件分页类,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

C语言return的用法有:1、对于返回值类型为void的函数,可以使用return语句来提前结束函数的执行;2、对于返回值类型不为void的函数,return语句的作用是将函数的执行结果返回给调用者;3、提前结束函数的执行,在函数内部,我们可以使用return语句来提前结束函数的执行,即使函数并没有返回值。

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

源码:publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#输出上述代码的输出可以简单地得出结论:return在finally之前执行,我们来看下字节码层面上发生了什么事情。下面截取case1方法的部分字节码,并且对照源码,将每个指令的含义注释在

第1部分:初始故障排除步骤检查苹果的系统状态:在深入研究复杂的解决方案之前,让我们从基础知识开始。问题可能不在于您的设备;苹果的服务器可能会关闭。访问Apple的系统状态页面,查看AppStore是否正常工作。如果有问题,您所能做的就是等待Apple修复它。检查您的互联网连接:确保您拥有稳定的互联网连接,因为“无法连接到AppStore”问题有时可归因于连接不良。尝试在Wi-Fi和移动数据之间切换或重置网络设置(“常规”>“重置”>“重置网络设置”>设置)。更新您的iOS版本:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

JavaScript 函数提供两个接口实现与外界的交互,其中参数作为入口,接收外界信息;返回值作为出口,把运算结果反馈给外界。下面本篇文章带大家了解一下JavaScript函数返回值,浅析下return语句的用法,希望对大家有所帮助!

Vue3.2setup语法糖是在单文件组件(SFC)中使用组合式API的编译时语法糖解决Vue3.0中setup需要繁琐将声明的变量、函数以及import引入的内容通过return向外暴露,才能在使用的问题1.在使用中无需return声明的变量、函数以及import引入的内容,即可在使用语法糖//import引入的内容import{getToday}from'./utils'//变量constmsg='Hello!'//函数func
