欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

使用 PHP 读取文本(TXT)文件 并分页显示_PHP教程

程序员文章站 2022-06-13 11:15:24
...
[PHP]代码 view source print?
01 //----------------you should save this file as m.php----------------
02 session_start();
03 if (empty($page)) {$page=1;}
04 if (isset($_GET['page'])==TRUE) {$page=$_GET['page']; }
05 ?>
06
07
08 "Content-Type" content="text/html; charset=UTF-8" />
09 www.qqview.com-Read Result
10 >
11
15
16
17
18 "100%"bgcolor="#CCCCCC">
19
20
21
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
27 function msubstr($str,$start,$len){
28 $strlength=$start+$len;
29 $tmpstr="";
30 for($i=0;$i$strlength;$i++) {
31 if(ord(substr($str,$i,1))==0x0a) {
32 $tmpstr.='
'
;
33 }
34 if(ord(substr($str,$i,1))>0xa0) {
35 $tmpstr.=substr($str,$i,2);
36 $i++;
37 }
38 else{
39 $tmpstr.=substr($str,$i,1); }
40 }
41 return $tmpstr;
42 }
43 //--------------------------截取中文字符串--------------------------
44 $c=msubstr($counter,0,($page-1)*5000);
45 $c1=msubstr($counter,0,$page*5000);
46 echo substr($c1,strlen($c),strlen($c1)-strlen($c));
47 }?>
48
49
50
51
52 "100%"bgcolor="#cccccc">
53
54 "42%" align="center" valign="middle">class="STYLE1"> echo $page;?> / echo $page_count;?> 页
55 "58%" height="28" align="left" valign="middle">
56 class="STYLE1">
57
58 echo "首页 ";
59 if($page!=1){
60 echo ".($page-1).">上一页 ";
61 }
62 if($page$page_count){
63 echo ".($page+1).">下一页 ";
64 }
65 echo ".$page_count.">尾页";
66 ?>
67
68
69
70
71

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/371822.htmlTechArticle[PHP]代码 view sourceprint? 01 ?php //----------------you should save this file as m.php---------------- 02 session_start(); 03 if ( empty ( $page )) { $page =1;} 04 if (isset( $...