Home  >  Article  >  Backend Development  >  PHP读取txt文本文件并分页显示的方法_php技巧

PHP读取txt文本文件并分页显示的方法_php技巧

WBOY
WBOYOriginal
2016-05-16 20:21:351152browse

本文实例讲述了PHP读取txt文本文件并分页显示的方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:
    session_start();
    if (empty($page)) {$page=1;}
    if (isset($_GET['page'])==TRUE) {$page=$_GET['page']; }
?>



Read Result








if($page){
$counter=file_get_contents("example.txt"); //读取txt文件内容到$counter
$length=strlen($counter);
$page_count=ceil($length/5000);
function msubstr($str,$start,$len){
    $strlength=$start+$len;
    $tmpstr="";
    for($i=0;$i     if(ord(substr($str,$i,1))==0x0a) {
        $tmpstr.='
';
    }
    if(ord(substr($str,$i,1))>0xa0) {
        $tmpstr.=substr($str,$i,2);
        $i++;
    }
    else{
        $tmpstr.=substr($str,$i,1); }
    }
    return $tmpstr;
}
//------------截取中文字符串---------
$c=msubstr($counter,0,($page-1)*5000);
$c1=msubstr($counter,0,$page*5000);
echo substr($c1,strlen($c),strlen($c1)-strlen($c));
}?>






/ 页

echo "首页 "; 
if($page!=1){
    echo "上一页 ";
}
if($page     echo "下一页 ";
}
echo "尾页"; 
?>


希望本文所述对大家的php程序设计有所帮助。

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