本篇內(nèi)容介紹了“PHP怎么讀取文本文件內(nèi)容并分頁顯示”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

功能很簡(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>“PHP怎么讀取文本文件內(nèi)容并分頁顯示”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
本文標(biāo)題:PHP怎么讀取文本文件內(nèi)容并分頁顯示-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://chinadenli.net/article48/cdcdhp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、服務(wù)器托管、企業(yè)網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)站改版、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容