PHP實(shí)現(xiàn)的超長(zhǎng)文本分頁(yè)顯示功能示例
本文實(shí)例講述了PHP實(shí)現(xiàn)的超長(zhǎng)文本分頁(yè)顯示功能。分享給大家供大家參考,具體如下:
一、代碼
1、index.php
<?php if ($_GET['page']=="") {$_GET['page']=1;}; include("function.php");?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>超長(zhǎng)文本的分頁(yè)顯示</title>
</head>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.STYLE3 {color: #333333; font-size: 13px; }
-->
</style>
<body>
<table width="876" height="638" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="343" height="159"> </td>
<td width="489"> </td>
<td width="44"> </td>
</tr>
<tr>
<td height="245"> </td>
<td align="center" valign="top"><table width="480" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="22" colspan="2">
<span class="STYLE3">
<?php
//讀取超長(zhǎng)文本中的數(shù)據(jù),實(shí)現(xiàn)超長(zhǎng)文本中數(shù)據(jù)的分頁(yè)顯示
if($_GET['page']){
$counter=file_get_contents("file/file.txt");
$length=strlen($counter);
$page_count=ceil($length/950);
$c=msubstr($counter,0,($_GET['page']-1)*950);
$c1=msubstr($counter,0,$_GET['page']*950);
echo substr($c1,strlen($c),strlen($c1)-strlen($c));
}
?>
</span> </td>
</tr>
<tr>
<td width="202" height="22"><span class="STYLE3">頁(yè)次:<?php echo $_GET['page'];?> / <?php echo $page_count;?> 頁(yè) </span></td>
<td width="278"><span class="STYLE3">分頁(yè):
<?php
if($_GET['page']!=1){
echo "<a href=index.php?page=1>首頁(yè)</a> ";
echo "<a href=index.php?page=".($_GET['page']-1).">上一頁(yè)</a> ";
}
if($_GET['page']<$page_count){
echo "<a href=index.php?page=".($_GET['page']+1).">下一頁(yè)</a> ";
echo "<a href=index.php?page=".$page_count.">尾頁(yè)</a>";
}
?>
</span></td>
</tr>
</table>
</td>
<td> </td>
</tr>
<tr>
<td height="234"> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
2、function.php
<?php
//定義一個(gè)用于截取一段字符串的函數(shù)msubstr()
function msubstr($str,$start,$len){ //$str指的是字符串,$start指的是字符串的起始位置,$len指的是長(zhǎng)度。
$strlen=$start+$len; //用$strlen存儲(chǔ)字符串的總長(zhǎng)度(從字符串的起始位置到字符串的總長(zhǎng)度)
for($i=0;$i<$strlen;$i++){ //通過(guò)for循環(huán)語(yǔ)句,循環(huán)讀取字符串
if(ord(substr($str,$i,1))>0xa0){ //如果字符串中首個(gè)字節(jié)的ASCII序數(shù)值大于0xa0,則表示為漢字
$tmpstr.=substr($str,$i,2); //每次取出兩位字符賦給變量$tmpstr,即等于一個(gè)漢字
$i++; //變量自加1
}else{ //如果不是漢字,則每次取出一位字符賦給變量$tmpstr
$tmpstr.=substr($str,$i,1);
}
}
return $tmpstr; //輸出字符串
}
?>
二、運(yùn)行結(jié)果

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》及《php正則表達(dá)式用法總結(jié)》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- 一個(gè)可分頁(yè)的基于文本的PHP留言板源碼
- PHP讀取txt文本文件并分頁(yè)顯示的方法
- PHP封裝分頁(yè)函數(shù)實(shí)現(xiàn)文本分頁(yè)和數(shù)字分頁(yè)
- PHP 文本文章分頁(yè)代碼 按標(biāo)記或長(zhǎng)度(不涉及數(shù)據(jù)庫(kù))
- PHP 讀取文本文件內(nèi)容并分頁(yè)顯示
- PHP函數(shù)實(shí)現(xiàn)分頁(yè)含文本分頁(yè)和數(shù)字分頁(yè)
- 一個(gè)典型的PHP分頁(yè)實(shí)例代碼分享
- 精美漂亮的php分頁(yè)類代碼
- php+mysql分頁(yè)代碼詳解
- PHP通用分頁(yè)類page.php[仿google分頁(yè)]
- php,ajax實(shí)現(xiàn)分頁(yè)
相關(guān)文章
WordPress網(wǎng)站訪問(wèn)慢解決方案細(xì)圖文教程
這篇文章主要介紹了WordPress網(wǎng)站訪問(wèn)慢解決方案細(xì)圖文教程,wordpress訪問(wèn)慢一直是一個(gè)比較頭疼的問(wèn)題,有正好需要的同學(xué)可以嘗試下,感覺(jué)不錯(cuò)的可以分享給大家2021-03-03

