傅令江的光影色彩世界
php长文章分页
2014-8-23 令狐江
<?php 
    error_reporting(E_ALL ^ E_NOTICE);
    if ($_GET['page']=="") {$_GET['page']=1;};  //判断变量的值是否为空
     
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<table width="750" height="174" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="35" align="center">&nbsp;</td>
    <td width="680" height="27" align="center"><strong></strong></td>
    <td width="35" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td align="left" valign="middle">&nbsp;</td>
    <td height="90" align="left" valign="middle"><table width="100%" height="52" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td bgcolor="#FFFFFF">
<?php   
 
    function unhtml($content){                              //定义自定义函数的名称
        $content=htmlspecialchars($content);                //转换文本中的特殊字符
           $content=str_replace(chr(13),"<br>",$content);     //替换文本中的换行符
        $content=str_replace(chr(32),"&nbsp;",$content);        //替换文本中的&nbsp;
        $content=str_replace("[_[","<",$content);            //替换文本中的大于号
        $content=str_replace(")_)",">",$content);            //替换文本中的小于号
        $content=str_replace("|_|"," ",$content);               //替换文本中的空格
        return trim($content);                              //删除文本中首尾的空格
    }
    //定义一个用于截取一段字符串的函数msubstr()
    function msubstr($str,$start,$len){     //$str指的是字符串,$start指的是字符串的起始位置,$len指的是长度。
    $strlen=$start+$len;                //用$strlen存储字符串的总长度(从字符串的起始位置到字符串的总长度)
    for($i=0;$i<$strlen;$i++){           //通过for循环语句,循环读取字符串
        if(ord(substr($str,$i,1))>0xa0){   //如果字符串中首个字节的ASCII序数值大于0xa0,则表示为汉字
        $tmpstr.=substr($str,$i,2);     //每次取出两位字符赋给变量$tmpstr,即等于一个汉字
        $i++;                       //变量自加1
        }else{                      //如果不是汉字,则每次取出一位字符赋给变量$tmpstr
            $tmpstr.=substr($str,$i,1);}
        }
    return $tmpstr;                     //输出字符串
    }
 
  if($_GET['page']){
     $counter=file_get_contents("file/file.txt");
     $length=strlen(unhtml($counter));
     $page_count=ceil($length/1050);
  
     $c=msubstr($counter,0,($_GET['page']-1)*1050);
     $c1=msubstr($counter,0,$_GET['page']*1050);
        echo substr($c1,strlen($c),strlen($c1)-strlen($c)); 
  }
   
  ?>
    </td>
      </tr>
    </table></td>
    <td align="left" valign="middle">&nbsp;</td>
  </tr>
</table>
<table width="680" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="42%" align="center" valign="middle" bgcolor="#FFFFFF"><span class="STYLE1">&nbsp;&nbsp;页次:<?php echo $_GET['page'];?> / <?php echo $page_count;?> 页 </span></td>
    <td width="58%" height="28" align="left" valign="middle" bgcolor="#FFFFFF"><span class="STYLE1"> &nbsp;分页:
             <?php
              if($_GET['page']!=1){   
                     echo  "<a href=mr_copyright.php?page=1>首页</a>&nbsp;";
                     echo "<a href=mr_copyright.php?page=".($_GET['page']-1).">上一页</a>&nbsp;";
                   }
                  if($_GET['page']<$page_count){
                        echo "<a href=mr_copyright.php?page=".($_GET['page']+1).">下一页</a>&nbsp;";
                        echo  "<a href=mr_copyright.php?page=".$page_count.">尾页</a>";               
                   }                   
              ?>     
    </span> </td>
  </tr>
</table>
</body>
</html>
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容