PHP 讀取文本文件內(nèi)容并分頁顯示
功能很簡(jiǎn)單,只是使用 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>
- 一個(gè)可分頁的基于文本的PHP留言板源碼
- PHP讀取txt文本文件并分頁顯示的方法
- PHP封裝分頁函數(shù)實(shí)現(xiàn)文本分頁和數(shù)字分頁
- PHP 文本文章分頁代碼 按標(biāo)記或長(zhǎng)度(不涉及數(shù)據(jù)庫)
- PHP函數(shù)實(shí)現(xiàn)分頁含文本分頁和數(shù)字分頁
- 一個(gè)典型的PHP分頁實(shí)例代碼分享
- 精美漂亮的php分頁類代碼
- php+mysql分頁代碼詳解
- PHP通用分頁類page.php[仿google分頁]
- php,ajax實(shí)現(xiàn)分頁
- PHP實(shí)現(xiàn)的超長(zhǎng)文本分頁顯示功能示例
相關(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-11
PHP正則表達(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-10
php workerman定時(shí)任務(wù)的實(shí)現(xiàn)代碼
這篇文章主要介紹了php workerman定時(shí)任務(wù)的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-12-12
yii框架表單模型使用及以數(shù)組形式提交表單數(shù)據(jù)示例
這篇文章主要介紹了yii框架表單模型使用及以數(shù)組形式提交表單數(shù)據(jù)示例,需要的朋友可以參考下2014-04-04
thinkphp 5框架實(shí)現(xiàn)登陸,登出及session登陸狀態(tài)檢測(cè)功能示例
這篇文章主要介紹了thinkphp 5框架實(shí)現(xiàn)登陸,登出及session登陸狀態(tài)檢測(cè)功能,結(jié)合實(shí)例形式分析了thinkPHP5登陸判斷、跳轉(zhuǎn)及session的相關(guān)使用技巧,需要的朋友可以參考下2019-10-10

