实现超长文本分页显示

一 代码
下载

1、index.php
Php代码    收藏代码
  1. <?php if ($_GET[page]=="") {$_GET[page]=1;};   include("function.php");?>  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5. <title>超长文本的分页显示</title>  
  6. </head>  
  7. <style type="text/css">  
  8. <!--  
  9. body {  
  10.     margin-left: 0px;  
  11.     margin-top: 0px;  
  12.     margin-right: 0px;  
  13.     margin-bottom: 0px;  
  14. }  
  15. a:link {  
  16.     text-decoration: none;  
  17. }  
  18. a:visited {  
  19.     text-decoration: none;  
  20. }  
  21. a:hover {  
  22.     text-decoration: none;  
  23. }  
  24. a:active {  
  25.     text-decoration: none;  
  26. }  
  27. .STYLE3 {color: #333333; font-size: 13px; }  
  28. -->  
  29. </style>  
  30. <body>  
  31.     <table width="876" height="638" border="0" align="center" cellpadding="0" cellspacing="0">  
  32.       <tr>  
  33.         <td width="343" height="159">&nbsp;</td>  
  34.         <td width="489">&nbsp;</td>  
  35.         <td width="44">&nbsp;</td>  
  36.       </tr>  
  37.       <tr>  
  38.         <td height="245">&nbsp;</td>  
  39.         <td align="center" valign="top"><table width="480" border="0" cellspacing="0" cellpadding="0">  
  40.         
  41.       <tr>  
  42.         <td height="22" colspan="2">  
  43.           <span class="STYLE3">  
  44.           <?php            
  45. //读取超长文本中的数据,实现超长文本中数据的分页显示  
  46.   if($_GET[page]){  
  47.      $counter=file_get_contents("file/file.txt");  
  48.      $length=strlen($counter);  
  49.      $page_count=ceil($length/950);  
  50.      $c=msubstr($counter,0,($_GET[page]-1)*950);  
  51.      $c1=msubstr($counter,0,$_GET[page]*950);  
  52.         echo substr($c1,strlen($c),strlen($c1)-strlen($c));   
  53.   }  
  54. ?>  
  55.           </span> </td>  
  56.       </tr>  
  57.        <tr>  
  58.         <td width="202" height="22"><span class="STYLE3">页次:<?php echo $_GET[page];?> / <?php echo $page_count;?> 页 </span></td>  
  59.         <td width="278"><span class="STYLE3">分页:  
  60.             <?php  
  61.               if($_GET[page]!=1){     
  62.                      echo  "<a href=index.php?page=1>首页</a>&nbsp;";  
  63.                      echo "<a href=index.php?page=".($_GET[page]-1).">上一页</a>&nbsp;";  
  64.                    }  
  65.                   if($_GET[page]<$page_count){  
  66.                         echo "<a href=index.php?page=".($_GET[page]+1).">下一页</a>&nbsp;";  
  67.                         echo  "<a href=index.php?page=".$page_count.">尾页</a>";                
  68.   下载                 }                     
  69.               ?>  
  70.         </span></td>  
  71.       </tr>  
  72. </table>  
  73. </td>  
  74.         <td>&nbsp;</td>  
  75.       </tr>  
  76.       <tr>  
  77.         <td height="234">&nbsp;</td>  
  78.         <td>&nbsp;</td>  
  79.         <td>&nbsp;</td>  
  80.       </tr>  
  81. </table>  
  82. </body>  
  83. </html>  
 
2、function.php下载
Php代码    收藏代码
  1. <?php  
  2. //定义一个用于截取一段字符串的函数msubstr()  
  3.     function msubstr($str,$start,$len){         //$str指的是字符串,$start指的是字符串的起始位置,$len指的是长度。  
  4.         $strlen=$start+$len;                    //用$strlen存储字符串的总长度(从字符串的起始位置到字符串的总长度)  
  5.         for($i=0;$i<$strlen;$i++){               //通过for循环语句,循环读取字符串  
  6.             if(ord(substr($str,$i,1))>0xa0){     //如果字符串中首个字节的ASCII序数值大于0xa0,则表示为汉字  
  7.                 $tmpstr.=substr($str,$i,2);     //每次取出两位字符赋给变量$tmpstr,即等于一个汉字  
  8.                 $i++;                           //变量自加1  
  9.             }else{                              //如果不是汉字,则每次取出一位字符赋给变量$tmpstr  
  10.                 $tmpstr.=substr($str,$i,1);  
  11.             }  
  12.         }  
  13.         return $tmpstr;                         //输出字符串  
  14.     }  
  15. ?>   
二 运行结果

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值