有戏

 找回密码
 立即注册
简历下载
搜索
热搜: 活动 交友 discuz
查看: 771|回复: 0

读取txt文件,并分页显示

[复制链接]

1000

主题

1002

帖子

25万

积分

论坛元老

Rank: 8Rank: 8

积分
251951
发表于 2015-1-17 09:28:56 | 显示全部楼层 |阅读模式


  1. <?php //----------------you should save this file as m.php----------------
  2.     session_start();
  3.     if (empty($page)) {$page=1;}
  4.     if (isset($_GET['page'])==TRUE) {$page=$_GET['page']; }
  5. ?>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <title>Read Result</title>
  10. <style type="text/css">
  11. <!--
  12. .STYLE1 {font-size: 12px}
  13. .STYLE2 {font-size: 18px}
  14. -->
  15. </style>
  16. </head>
  17. <body>
  18. <table width="100%"  bgcolor="#CCCCCC">
  19. <tr>
  20. <td >
  21. <?php
  22. if($page){
  23. $counter=file_get_contents("example.txt"); //-------read the file into a string.-------
  24. $length=strlen($counter);
  25. $page_count=ceil($length/5000);

  26. function msubstr($str,$start,$len){
  27.     $strlength=$start+$len;
  28.     $tmpstr="";
  29.     for($i=0;$i<$strlength;$i++) {
  30.     if(ord(substr($str,$i,1))==0x0a) {
  31.         $tmpstr.='<br />';
  32.     }
  33.     if(ord(substr($str,$i,1))>0xa0) {
  34.         $tmpstr.=substr($str,$i,2);
  35.         $i++;
  36.     }
  37.     else{
  38.         $tmpstr.=substr($str,$i,1); }
  39.     }
  40.     return $tmpstr;
  41. }
  42. //--------------------------截取中文字符串--------------------------
  43. $c=msubstr($counter,0,($page-1)*5000);
  44. $c1=msubstr($counter,0,$page*5000);
  45. echo substr($c1,strlen($c),strlen($c1)-strlen($c));
  46. }?>
  47. </td>
  48. </tr>
  49. </table>

  50. <table width="100%"  bgcolor="#cccccc">
  51. <tr>
  52. <td width="42%" align="center" valign="middle"><span class="STYLE1"> <?php echo $page;?> / <?php echo $page_count;?> 页 </span></td>
  53. <td width="58%" height="28" align="left" valign="middle">
  54. <span class="STYLE1">
  55. <?php
  56. echo "<a href=m.php?page=1>首页</a> ";  
  57. if($page!=1){
  58.     echo "<a href=m.php?page=".($page-1).">上一页</a> ";
  59. }
  60. if($page<$page_count){
  61.     echo "<a href=m.php?page=".($page+1).">下一页</a> ";
  62. }
  63. echo "<a href=m.php?page=".$page_count.">尾页</a>";  
  64. ?>
  65. </span> </td>
  66. </tr>
  67. </table>
  68. </body>
  69. </html>

复制代码
大家好
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|有戏 粤ICP备2020111303号

GMT+8, 2025-12-6 13:45 , Processed in 0.106489 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表