php超长文本的分页

来源:互联网 发布:cf刷枪软件2016 编辑:程序博客网 时间:2024/04/30 12:02

index.php代码:

<?php session_start(); if ($page=="") {$page=1;};?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>超长文本的分页显示</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
.STYLE2 {font-size: 13px}
-->
</style>
</head>
<body>
<table width="450" height="285" border="0" cellpadding="0" cellspacing="0" >
<tr>
    <td align="center">&nbsp;</td>
    <td height="50" align="center"><strong>超长文本的分页显示</strong></td>
    <td align="center">&nbsp;</td>
</tr>
<tr>
    <td width="97" align="left" valign="middle">&nbsp;</td>
    <td width="270" align="left" valign="middle"><span class="STYLE2">&nbsp;&nbsp;
<?php 
if($page){
$fp=fopen("file/file.txt","r");
$counter=fgets($fp);
     $length=strlen($counter);
     $page_count=ceil($length/200);
     $fp=fopen("file/file.txt","r");
   include("function.php");
     $c=msubstr($counter,0,($page-1)*200);
     $c1=msubstr($counter,0,$page*200);
   echo substr($c1,strlen($c),strlen($c1)-strlen($c)); 
}?>
    </span></td>
    <td width="75" align="left" valign="middle">&nbsp;</td>
</tr>
<tr>
    <td height="30" align="center">&nbsp;</td>
    <td height="30" align="center"><table width="270" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="42%" align="center" valign="middle"><span class="STYLE1">&nbsp;&nbsp;页次:<?php echo $page;?> / <?php echo $page_count;?> 页 </span></td>
        <td width="58%" height="28" align="left" valign="middle"><span class="STYLE1"> &nbsp;分页:
          <?php
       if($page!=1){   
         echo "<a href=index.php?page=1>首页</a>&nbsp;";
      echo "<a href=index.php?page=".($page-1).">上一页</a>&nbsp;";
       }
      if($page<$page_count){
            echo "<a href=index.php?page=".($page+1).">下一页</a>&nbsp;";
            echo "<a href=index.php?page=".$page_count.">尾页</a>";    
       }       
     ?>
        </span> </td>
      </tr>
    </table></td>
    <td height="30" align="center">&nbsp;</td>
</tr>
<tr>
    <td height="35" colspan="3" align="center">&nbsp;</td>
</tr>
</table>
</body>
</html>

function.php 代码:

<?php
function msubstr($str,$start,$len){   
$strlen=$start+$len; 
    for($i=0;$i<$strlen;$i++) { 
       if(ord(substr($str,$i,1))>0xa0) { 
          $tmpstr.=substr($str,$i,2); 
          $i++;
        }else{
    $tmpstr.=substr($str,$i,1); } 
    } 
    return $tmpstr; 
}
?>

原创粉丝点击