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

php中文网
发布: 2016-07-22 09:03:03
原创
1245人浏览过

[php]代码

芦笋演示
芦笋演示

一键出成片的录屏演示软件,专为制作产品演示、教学课程和使用教程而设计。

芦笋演示 34
查看详情 芦笋演示
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( $...
相关标签:
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号