Home > Backend Development > PHP Tutorial > PHP article pagination_PHP tutorial

PHP article pagination_PHP tutorial

WBOY
Release: 2016-07-13 17:51:56
Original
1087 people have browsed it

1.  2. /*文章分页代码*/ 
3.  
4. $fp=fopen('txt.txt','r'); 
5. while (!feof($fp)){ 
6.      $content.=fgets($fp);  
7. } 
8. $c_page=""; 
9. if(isset($_GET['page'])) $c_page=$_GET['page'];  
10. $listlen=100;   //分页显示字符数  
11. $conlen=strlen($content);   //内容长度  
12. $j=0; 
13. $listat[0]=0; 
14. $lookat=0; 
15. for ($i=1;$i<$conlen/$listlen+1;$i++){ 
16.     //echo $conlen/$listlen;  
17.     if($lookat<$listlen) 
18.         $lookat=$listlen; 
19.         if($lookat>$conlen){ 
20.             $j++; 
21.             $listat[$j]=$conlen; 
22.             break; 
23.         } 
24.     $endat=strpos($content,"n",$lookat); 
25.     if($endat>$conlen-$listlen/5 or intval($endat)<1){ 
26.         $j++; 
27.         $listat[$j]=$conlen; 
28.         break; 
29.     }else { 
30.         $j++; 
31.         $listat[$j]=$endat; 
32.         $lookat=$endat+$listlen; 
33.     } 
34.          
35. } 
36. //print page  
37. $pagenum=$j;  //总页数  
38. $page=intval($c_page); 
39. if(emptyempty($page) or $page<1 or $page>$pagenum) $page=1; 
40. if($pagenum >1)  
41. for ($i=1;$i<$pagenum+1;$i++){ 
42.     echo " {$i} "; 
43. } 
44. echo "
"; 
45. $stag=$page-1; 
46. $startb=$listat[$stag]; 
47. if($startb>0) //去除首个换行  www.2cto.com
48. $startb=$startb+1; 
49. $cont=substr($content,$startb,$listat[$page]-$startb); 
50. echo "
文章内容:
"; 
51. if($page>1) 
52. echo "[接上页]       "; 
53. echo $cont; 
54.  
55. ?> 
 
作者:chaojie2009

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478163.htmlTechArticle1.?php 2./*文章分页代码*/ 3. 4.$fp=fopen(txt.txt,r); 5.while (!feof($fp)){ 6. $content.=fgets($fp); 7.} 8.$c_page=; 9.if(isset($_GET[page])) $c_page=$_GET[page]; 10.$listlen=1...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template