使用PHP读取文本(TXT)文件并分页显示_PHP教程
                        
                            时间:2021-07-01 10:21:17
                            帮助过:33人阅读
							                        
                     
                    
                    [PHP]代码
view source
 
print?
    
        
            | 03 |     if(empty($page)) {$page=1;}  | 
    
    
        
            | 04 |     if(isset($_GET['page'])==TRUE) {$page=$_GET['page']; }  | 
    
    
        
            | 08 | "Content-Type"content="text/html; charset=UTF-8"/>   | 
    
    
        
            | 09 | www.qqview.com-Read Result   | 
    
    
        
            | 18 | "100%"bgcolor="#CCCCCC">  
 
    
        
            | 23 | $counter=file_get_contents("example.txt");  |  
    
        
            | 24 | $length=strlen($counter);   |  
    
        
            | 25 | $page_count=ceil($length/5000);   |  
    
        
            | 27 | functionmsubstr($str,$start,$len){   |  
    
        
            | 28 |     $strlength=$start+$len;   |  
    
        
            | 30 |     for($i=0;$i<$strlength;$i++) {   |  
    
        
            | 31 |     if(ord(substr($str,$i,1))==0x0a) {   |  
    
        
            | 34 |     if(ord(substr($str,$i,1))>0xa0) {   |  
    
        
            | 35 |         $tmpstr.=substr($str,$i,2);   |  
    
        
            | 39 |         $tmpstr.=substr($str,$i,1); }   |  
    
        
            | 44 | $c=msubstr($counter,0,($page-1)*5000);   |  
    
        
            | 45 | $c1=msubstr($counter,0,$page*5000);   |  
    
        
            | 46 | echosubstr($c1,strlen($c),strlen($c1)-strlen($c));   |  | 
    
    
        
            | 52 | "100%"bgcolor="#cccccc">  
 
    
        
            | 54 | | "42%"align="center"valign="middle">class="STYLE1"> echo$page;?> / echo$page_count;?> 页  |  |  
    
        
            | 55 | | "58%"height="28"align="left"valign="middle">  |  |  
    
        
            | 60 |     echo".($page-1).">上一页 ";   |  
    
        
            | 62 | if($page<$page_count){   |  
    
        
            | 63 |     echo".($page+1).">下一页 ";   |  
    
        
            | 65 | echo".$page_count.">尾页";    |  | 
    
http://www.bkjia.com/PHPjc/371822.htmlwww.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( $...