偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

方便快捷的PHP長(zhǎng)文章分頁(yè)函數(shù)

開發(fā) 后端
我們?cè)谶@篇文章中為大家展現(xiàn)了PHP長(zhǎng)文章分頁(yè)函數(shù)的代碼示例,希望能夠通過本文掌握分頁(yè)代碼的運(yùn)用,靈活運(yùn)用,方便編程。

 PHP程序員們?cè)诰帉懗绦虼a的時(shí)候,通常都會(huì)用到文章的分頁(yè)等功能的實(shí)現(xiàn)。每次編寫不同的程序都需要編寫一遍文章分頁(yè)的代碼,比較瑪法。#t#

今天我們就為大家寫了一段PHP長(zhǎng)文章分頁(yè)函數(shù),方便大家的代碼編寫:

  1. < ?php   
  2. function ff_page($content,$page)   
  3. {   
  4. global $expert_id;   
  5. $PageLength = 2000; //每頁(yè)字?jǐn)?shù)   
  6. $CLength = strlen($content);   
  7. $PageCount = floor(($CLength 
    / $PageLength)) + 1; //計(jì)算頁(yè)數(shù)   
  8. $PageArray=array();   
  9. $Seperator = array("\n",
    "\r","。","!","?",";
    ",",","”","’"); //分隔符號(hào)   
  10. //echo "頁(yè)數(shù):".$PageCount."< br>";   
  11. //echo "長(zhǎng)度:".$CLength."< br>< br>< br>";   
  12. //strpos() 函數(shù)返回字符串在
    另一個(gè)字符串中第一次出現(xiàn)的位置   
  13. if($CLength<$PageLength)   
  14. {   
  15. echo $content;   
  16. }else{   
  17. $PageArray[0]=0;   
  18. $Pos = 0;   
  19. $i=0;   
  20. //第一頁(yè)   
  21. for($j=0;$j< sizeof($Seperator);$j++)   
  22. {   
  23. //echo $Seperator[$j];   
  24. $Pos=strpos($content,
    $Seperator[$j],$PageArray[$i]+1900);   
  25. while($Pos > 0 && $Pos
     
    < ($i+1)*$PageLength && 
    $Pos 
    > $i*$PageLength )   
  26. {   
  27. $PageArray[$i] = $Pos ;   
  28. $Pos = strpos($Pos+$PageLength,
    $content,$Seperator[$j]) ;   
  29. }   
  30. if($PageArray[$i]>0)   
  31. {   
  32. $j = $j + sizeof($Seperator) + 1;   
  33. }   
  34. }   
  35. //---   
  36. for($i=1;$i< $PageCount-1;$i++){   
  37. for($j=0;$j< sizeof($Seperator);$j++)   
  38. {   
  39. //echo $Seperator[$j];   
  40. $Pos=strpos($content,$Seperator
    [$j],$PageArray[$i-1]+1900);   
  41. while($Pos > 0 && $Pos < 
    ($i+1)*$PageLength && $Pos 
    > 
    $i*$PageLength )   
  42. {   
  43. $PageArray[$i] = $Pos ;   
  44. $Pos = strpos($Pos+$PageLength,
    $content,$Seperator[$j]) ;   
  45. }   
  46. if($PageArray[$i]>0)   
  47. {   
  48. $j = $j + sizeof($Seperator) + 1;   
  49. }   
  50. }   
  51. }   
  52. //--PHP長(zhǎng)文章分頁(yè)函數(shù)最后一頁(yè)   
  53. $PageArray[$PageCount-1]=$CLength;   
  54. //$page=2;   
  55. if($page==1)   
  56. {   
  57. $output=substr($content,0,
    $PageArray[$page-1]+2);   
  58. }   
  59. if($page>1 && $page< =$PageCount)   
  60. {   
  61. $output=substr($content,$PageArray
    [$page-2]+2,$PageArray[$page-1]-$
    PageArray[$page-2]);   
  62. $output=" (上接第".($page-1)."頁(yè))\n".$output;   
  63. }   
  64. echo str_replace("\n","< br>&nbsp;
    &nbsp;&nbsp;",$output);   
  65. //if($page==$PageCount)   
  66. //return $output=substr($content,
    $PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]);   
  67. if($PageCount>1)   
  68. {   
  69. echo "< br>< br>< br>< center>";   
  70. echo "<font color='ff0000'>".$page."< /font>/".$PageCount." 頁(yè) &nbsp;";   
  71. if($page>1)   
  72. echo "< a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page-1).">上一頁(yè)< /a> ";   
  73. else   
  74. echo "上一頁(yè) ";   
  75. for($i=1;$i< =$PageCount;$i++)   
  76. {   
  77. echo "< a href=$PHP_SELF?expert_id=$expert_id&page_t=".$i.">[".$i."]< /a> ";   
  78. }   
  79. if($page<$PageCount)   
  80. echo " < a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page+1).">下一頁(yè)< /a> ";   
  81. else   
  82. echo " 下一頁(yè) ";   
  83. echo "< /center>";   
  84. }   
  85. }   
  86. }?>  

PHP長(zhǎng)文章分頁(yè)函數(shù)的使用
 

  1. < ?php   
  2. $content1=''測(cè)試文字,
    盡量長(zhǎng)一些,www.corange.cn";   
  3. $current=$_REQUEST['page_t'];   
  4. $result=ff_page
    ($content1,$current);   
  5. echo $result;   
  6. ?>  

PHP長(zhǎng)文章分頁(yè)函數(shù)的使用與實(shí)現(xiàn)的代碼示例如上所示。

責(zé)任編輯:曹凱 來源: cnblogs.com
相關(guān)推薦

2022-04-21 07:34:34

JDK8JDK7數(shù)據(jù)

2022-04-21 09:48:54

JDK8JDK7編碼

2015-05-07 14:33:18

HTML 5編輯器中文詳解

2021-08-05 16:36:16

Windows 11操作系統(tǒng)微軟

2013-11-28 10:40:55

2021-08-08 14:15:30

Windows 11Windows微軟

2017-04-21 09:30:40

2009-12-08 15:48:19

PHP文章分頁(yè)

2020-02-17 10:34:04

箭頭函數(shù)開發(fā) JavaScript

2014-09-25 14:15:36

微信企業(yè)號(hào)案例

2009-12-03 09:49:59

PHP分頁(yè)導(dǎo)航函數(shù)

2021-10-09 21:34:13

數(shù)字人民幣微信支付寶

2011-05-04 14:55:09

SP-L355三星投影機(jī)

2009-12-10 16:40:04

PHP處理分頁(yè)

2009-12-03 09:00:18

PHP分頁(yè)函數(shù)

2010-04-16 11:31:29

Oracle分頁(yè)存儲(chǔ)過

2011-04-21 17:09:09

掃描儀

2009-12-02 18:51:12

PHP分頁(yè)類

2010-04-14 10:31:05

2011-05-06 14:12:49

投影機(jī)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)