Home >Backend Development >PHP Tutorial >Convenient and fast PHP long article paging function_PHP tutorial

Convenient and fast PHP long article paging function_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:32:08854browse

Today we have written a PHP long article paging function for you to facilitate your code writing:

  1. < ?php
  2. function ff_page($content,$page)
  3. {
  4. global $expert_id;
  5. $PageLength = 2000; //Number of words per page
  6. $CLength = strlen($content);
  7. (($CLength
  8. / $PageLength)) + 1; //Calculate the number of pages $PageArray=
    array
  9. (); 🎜>array
  10. ("n", "r",".","!","?","; ",",",""","' "); //Delimiter //echo "Page count: ".$PageCount."<
  11. br>"; //echo "Length: ".$CLength."

    < ;
  12. br>< br> ;
  13. <
  14. br>"; //strpos() function returns the position of the first occurrence of a string in another string if($CLength<$PageLength) { echo $content;

  15. }else {
  16. $PageArray[0]=0; $
  17. Pos
  18. =
  19. 0
  20. ; 🎜>;
  21. //First page
  22. for($
  23. j
  24. =0;$j<
  25. sizeof
  26. ($Seperator);$j++) { //echo $Seperator[$j];
  27. $
  28. Pos
  29. =strpos($content, $Seperator[$j],$PageArray[$i]+1900); while($Pos > 0 && $Pos <
  30. ($i+1)*$PageLength &&
  31. $Pos >
  32. $i*$PageLength )
  33. { $PageArray[$i] = $Pos ; $
    Pos
  34. =
  35. strpos($Pos+$PageLength,$content,$Seperator[$j]) ;   
  36. }   
  37. if($PageArray[$i]>0)   
  38. {   
  39. $j = $j + sizeof($Seperator) + 1;   
  40. }   
  41. }   
  42. //---   
  43. for($i=1;$i< $PageCount-1;$i++){   
  44. for($j=0;$j< sizeof($Seperator);$j++)   
  45. {   
  46. //echo $Seperator[$j];   
  47. $Pos=strpos($content,$Seperator
    [$j],$PageArray[$i-1]+1900);   
  48. while($Pos > 0 && $Pos < 
    ($i+1)*$PageLength && $Pos 
    > 
    $i*$PageLength )   
  49. {   
  50. $PageArray[$i] = $Pos ;   
  51. $Pos = strpos($Pos+$PageLength,
    $content,$Seperator[$j]) ;   
  52. }   
  53. if($PageArray[$i]>0)   
  54. {   
  55. $j = $j + sizeof($Seperator) + 1;   
  56. }   
  57. }   
  58. }   
  59. //--PHP长文章分页函数最后一页   
  60. $PageArray[$PageCount-1]=$CLength;   
  61. //$page=2;   
  62. if($page==1)   
  63. {   
  64. $output=substr($content,0,
    $PageArray[$page-1]+2);   
  65. }   
  66. if($page>1 && $page< =$PageCount)   
  67. {   
  68. $output=substr($content,$PageArray
    [$page-2]+2,$PageArray[$page-1]-$
    PageArray[$page-2]);   
  69. $output=" (上接第".($page-1)."页)n".$output;   
  70. }   
  71. echo str_replace("n","< br> 
      ",$output);   
  72. //if($page==$PageCount)   
  73. //return $output=substr($content,
    $PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]);   
  74. if($PageCount>1)   
  75. {   
  76. echo "< br>< br>< br>< center>";   
  77. echo "<font color='ff0000'>".$page."< /font>/".$PageCount." 页  ";   
  78. if($page>1)   
  79. echo "< a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page-1).">上一页< /a> ";   
  80. else   
  81. echo "上一页 ";   
  82. for($i=1;$i< =$PageCount;$i++)   
  83. {   
  84. echo "< a href=$PHP_SELF?expert_id=$expert_id&page_t=".$i.">[".$i."]< /a> ";   
  85. }   
  86. if($page<$PageCount)   
  87. echo " < a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page+1).">下一页< /a> ";   
  88. else   
  89. echo " 下一页 ";   
  90. echo "< /center>";   
  91. }   
  92. }   
  93. }?>  

PHP长文章分页函数的使用
 

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php   </span></span></li><li><span>$</span><span class="attribute">content1</span><span>=</span><span class="attribute-value">''</span><span>测试文字,<br />尽量长一些,www.corange.cn";   </span></li><li class="alt"><span>$</span><span class="attribute">current</span><span>=$_REQUEST['page_t'];   </span></li><li><span>$</span><span class="attribute">result</span><span>=</span><span class="attribute-value">ff_page<br /></span><span>($content1,$current);   </span></li><li class="alt"><span>echo $result;   </span></li><li><span class="tag">?></span><span>  </span></span></li></ol>

PHP长文章分页函数的使用与实现的代码示例如上所示。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446155.htmlTechArticle今天我们就为大家写了一段PHP长文章分页函数,方便大家的代码编写: ?php functionff_page($content,$page) { global$expert_id; $ PageLength = 2000 ;//每页字...
Statement:
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