PHP 讀取文本文件內(nèi)容并分頁顯示
更新時間:2016年01月02日 16:14:17 作者:mickelfeng
本文給大家分享的代碼非常簡單實用,使用php實現(xiàn)讀取文本文件內(nèi)容,并且分頁展示出來,有類似需求的小伙伴可以來參考下。
功能很簡單,只是使用 PHP 讀取文本(TXT)文件 并分頁顯示
<?php //----------------you should save this file as m.php---------------- session_start(); if (empty($page)) {$page=1;} if (isset($_GET['page'])==TRUE) {$page=$_GET['page']; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Read Result</title> <style type="text/css"> <!-- .STYLE1 {font-size: 12px} .STYLE2 {font-size: 18px} --> </style> </head> <body> <table width="100%" bgcolor="#CCCCCC"> <tr> <td > <?php if($page){ $counter=file_get_contents("example.txt"); //-------read the file into a string.------- $length=strlen($counter); $page_count=ceil($length/5000); function msubstr($str,$start,$len){ $strlength=$start+$len; $tmpstr=""; for($i=0;$i<$strlength;$i++) { if(ord(substr($str,$i,1))==0x0a) { $tmpstr.='<br />'; } 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)); }?> </td> </tr> </table> <table width="100%" bgcolor="#cccccc"> <tr> <td width="42%" align="center" valign="middle"><span class="STYLE1"> <?php echo $page;?> / <?php echo $page_count;?> 頁 </span></td> <td width="58%" height="28" align="left" valign="middle"> <span class="STYLE1"> <?php echo "<a href=m.php?page=1>首頁</a> "; if($page!=1){ echo "<a href=m.php?page=".($page-1).">上一頁</a> "; } if($page<$page_count){ echo "<a href=m.php?page=".($page+1).">下一頁</a> "; } echo "<a href=m.php?page=".$page_count.">尾頁</a>"; ?> </span> </td> </tr> </table> </body> </html>
相關(guān)文章
ThinkPHP實現(xiàn)動態(tài)包含文件的方法
這篇文章主要介紹了ThinkPHP實現(xiàn)動態(tài)包含文件的方法,是進行ThinkPHP項目開發(fā)中非常實用的技巧,需要的朋友可以參考下2014-11-11純真IP數(shù)據(jù)庫的應用 IP地址轉(zhuǎn)化成十進制
由于純真數(shù)據(jù)庫中的IP數(shù)據(jù)是和普通IP不同的,所以要轉(zhuǎn)化后才能比對2009-06-06淺談PHP array_search 和 in_array 函數(shù)效率問題
這篇文章主要介紹了淺談PHP array_search 和 in_array 函數(shù)效率問題,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10yii框架表單模型使用及以數(shù)組形式提交表單數(shù)據(jù)示例
這篇文章主要介紹了yii框架表單模型使用及以數(shù)組形式提交表單數(shù)據(jù)示例,需要的朋友可以參考下2014-04-04thinkphp 5框架實現(xiàn)登陸,登出及session登陸狀態(tài)檢測功能示例
這篇文章主要介紹了thinkphp 5框架實現(xiàn)登陸,登出及session登陸狀態(tài)檢測功能,結(jié)合實例形式分析了thinkPHP5登陸判斷、跳轉(zhuǎn)及session的相關(guān)使用技巧,需要的朋友可以參考下2019-10-10