search

/**
 * 文件分页类 
 */
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; 
 }
}

Use as follows

<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();

The above introduces the PHP file paging class, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
华为GT3 Pro和GT4的差异是什么?华为GT3 Pro和GT4的差异是什么?Dec 29, 2023 pm 02:27 PM

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

C语言return的用法详解C语言return的用法详解Oct 07, 2023 am 10:58 AM

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

修复:截图工具在 Windows 11 中不起作用修复:截图工具在 Windows 11 中不起作用Aug 24, 2023 am 09:48 AM

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

Java中return和finally语句的执行顺序是怎样的?Java中return和finally语句的执行顺序是怎样的?Apr 25, 2023 pm 07:55 PM

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

如何修复无法连接到iPhone上的App Store错误如何修复无法连接到iPhone上的App Store错误Jul 29, 2023 am 08:22 AM

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

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决Jun 13, 2016 am 10:23 AM

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

详解JavaScript函数返回值和return语句详解JavaScript函数返回值和return语句Aug 04, 2022 am 09:46 AM

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

Vue3怎么使用setup语法糖拒绝写returnVue3怎么使用setup语法糖拒绝写returnMay 12, 2023 pm 06:34 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor