html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

PHP超长文本的分页显示_PHP教程_编程技术

[ ] 已经帮助:人解决问题

PHP实现超长文本的分页显示,如下代码:ymdHTML5中文学习网 - HTML5先行者学习网

  1. <?php  
  2. session_start(); 
  3.  if(isset($_REQUEST['page'])) 
  4.  { 
  5.    $page = intval($_GET['page']); 
  6.  } 
  7.  else 
  8.  { 
  9.    $page = 1
  10.  } 
  11.  ?> 
  12. <html> 
  13. <head> 
  14. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  15. <title>超长文本的分页显示 - www.cxybl.com</title> 
  16. <style type="text/css"> 
  17. <!-- 
  18. .STYLE1 {font-size: 12px}a 
  19. .STYLE2 {font-size: 13px} 
  20. --> 
  21. </style> 
  22. </head> 
  23. <body> 
  24. <table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#9AFAFC"> 
  25.   <tr> 
  26.     <td height="27" align="center"><strong>超长文本的分页显示</strong></td> 
  27.   </tr> 
  28.   <tr> 
  29.     <td height="90" align="left" valign="middle"><span class="STYLE2">   
  30. <?php  
  31.   if($page){ 
  32.      $fp=fopen("file/file.txt","r"); 
  33.      $counter=fgets($fp); 
  34.      $length=strlen($counter); 
  35.      $page_count=ceil($length/200); 
  36.      $fp=fopen("file/file.txt","r"); 
  37.    include("function.php"); 
  38.      $c=msubstr($counter,0,($page-1)*200); 
  39.      $c1=msubstr($counter,0,$page*200); 
  40.         echo substr($c1,strlen($c),strlen($c1)-strlen($c));  
  41.   }?> 
  42.     </span></td> 
  43.   </tr> 
  44. </table> 
  45. <table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#9AFAFC"> 
  46.   <tr> 
  47.     <td width="42%" align="center" valign="middle"> 
  48.  <span class="STYLE1">  页次:<?php echo $page;?> / <?php echo $page_count;?> 页 </span></td> 
  49.     <td width="58%" height="28" align="left" valign="middle"><span class="STYLE1">  分页: 
  50.              <?php 
  51.               if($page!=1){    
  52.                      echo  "<a href=index.php?page=1>首页</a> "; 
  53.                      echo "<a href=index.php?page=".($page-1).">上一页</a> "; 
  54.                    } 
  55.                   if($page<$page_count){ 
  56.                         echo "<a href=index.php?page=".($page+1).">下一页</a> "; 
  57.                         echo  "<a href=index.php?page=".$page_count.">尾页</a>";               
  58.                    }                    
  59.               ?>      
  60.     </span> </td> 
  61.   </tr> 
  62. </table> 
  63. </body> 
  64. </html> 

function.php:ymdHTML5中文学习网 - HTML5先行者学习网

  1. <?php 
  2. function msubstr($str,$start,$len){    
  3.     $strlen=$start+$len;  
  4.     for($i=0;$i<$strlen;$i++) {  
  5.        if(ord(substr($str,$i,1))>0xa0) {  
  6.           $tmpstr.=substr($str,$i,2);  
  7.           $i++; 
  8.         }else
  9.           $tmpstr.=substr($str,$i,1); }  
  10.     }  
  11.     return $tmpstr;  
  12. ?> 

conn.php:ymdHTML5中文学习网 - HTML5先行者学习网

  1. <?php  
  2. $id=mysql_connect("localhost","root","mysql"or die('连接失败:' . mysql_error()); 
  3. if(mysql_select_db("phpjcdb",$id))  //说明:phpjcdb 是数据库名称 
  4.   echo ""
  5.   else 
  6.   echo ('数据库选择失败:' . mysql_error()); 
  7. mysql_query("set names gb2312");  //设置为简体中文 
  8. ?> 
ymdHTML5中文学习网 - HTML5先行者学习网
ymdHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助