首页 >后端开发 >php教程 >使用 PHP 读取文本(TXT)文件 并分页显示_PHP教程

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

WBOY
WBOY原创
2016-07-22 09:03:031017浏览

[PHP]代码

view source   print?
01 <?php //----------------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 <meta http-equiv="</code"> <code class="php string">"Content-Type"content="text/html; charset=UTF-8"/> 
09 <title>www.qqview.com-Read Result</title> 
10 <style type="</code"><code class="php string">"text/css"</style>
11 <!--
12 .STYLE1 {font-size: 12px}
13 .STYLE2 {font-size: 18px}
14 --> 
15
16
17
18 <table width="</code"> <code class="php string">"100%"bgcolor="#CCCCCC"
19
20
21 <?php
22 if($page){ 
23 $counter=file_get_contents("example.txt"); //-------read the file into a string.-------
24 $length=strlen($counter); 
25 <code class="php variable">$page_count=ceil($length/5000); 
26  
27 functionmsubstr($str,$start,$len){ 
28     <code class="php variable">$strlength=$start+$len
29     $tmpstr="";
30     for($i=0;$i<code class="php variable">$strlength;$i++) { 
31     if(ord(substr($str,$i,1))==0x0a) { 
32         $tmpstr.='<br>';
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 echosubstr($c1,strlen($c),strlen($c1)-strlen($c)); 
47 }?> 
48
49
50
51  
52 <table width="</code"> <code class="php string">"100%"bgcolor="#cccccc"
53
54 <td width="</code"> <code class="php string">"42%"align="center"valign="middle"><span><code class="php keyword">class="STYLE1"> <?php echo$page;?> / <?php echo;?> 页
55 <td width="</code"> <code class="php string">"58%"height="28"align="left"valign="middle">
56 ="STYLE1">
57 <?php
58 echo"首页;  
59 if($page!=1){ 
60     echo"<a href="m.php?page=%22</code"><code class="php plain">.($page-1).">上一页
61
62 if($page<code class="php variable">$page_count){ 
63     echo"<a href="m.php?page=%22</code"><code class="php plain">.($page+1).">下一页
64 }
65 echo"<a href="m.php?page=%22</code"><code class="php plain">.<code class="php variable">$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( $...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn