PHP 讀取文本文件內(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實(shí)現(xiàn)動(dòng)態(tài)包含文件的方法
這篇文章主要介紹了ThinkPHP實(shí)現(xiàn)動(dòng)態(tài)包含文件的方法,是進(jìn)行ThinkPHP項(xiàng)目開發(fā)中非常實(shí)用的技巧,需要的朋友可以參考下2014-11-11PHP正則表達(dá)式過濾html標(biāo)簽屬性(DEMO)
這篇文章主要介紹了PHP正則表達(dá)式過濾html標(biāo)簽屬性的相關(guān)內(nèi)容,實(shí)用性非常,感興趣的朋友參考下吧2016-05-05純真IP數(shù)據(jù)庫的應(yīng)用 IP地址轉(zhuǎn)化成十進(jìn)制
由于純真數(shù)據(jù)庫中的IP數(shù)據(jù)是和普通IP不同的,所以要轉(zhuǎn)化后才能比對(duì)2009-06-06淺談PHP array_search 和 in_array 函數(shù)效率問題
這篇文章主要介紹了淺談PHP array_search 和 in_array 函數(shù)效率問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10php workerman定時(shí)任務(wù)的實(shí)現(xiàn)代碼
這篇文章主要介紹了php workerman定時(shí)任務(wù)的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-12-12yii框架表單模型使用及以數(shù)組形式提交表單數(shù)據(jù)示例
這篇文章主要介紹了yii框架表單模型使用及以數(shù)組形式提交表單數(shù)據(jù)示例,需要的朋友可以參考下2014-04-04thinkphp 5框架實(shí)現(xiàn)登陸,登出及session登陸狀態(tài)檢測功能示例
這篇文章主要介紹了thinkphp 5框架實(shí)現(xiàn)登陸,登出及session登陸狀態(tài)檢測功能,結(jié)合實(shí)例形式分析了thinkPHP5登陸判斷、跳轉(zhuǎn)及session的相關(guān)使用技巧,需要的朋友可以參考下2019-10-10