検索
ホームページphp教程php手册方便快捷的PHP长文章分页函数

方便快捷的PHP长文章分页函数

Jun 13, 2016 am 11:09 AM
php関数ページネーション私たち記事

今天我们就为大家写了一段PHP长文章分页函数,方便大家的代码编写:

  1.  ?php   
  2. function ff_page($content,$page)   
  3. {   
  4. global $expert_id;   
  5. $PageLength = 2000; //每页字数   
  6. $CLength = strlen($content);   
  7. $PageCount = floor(($CLength 
    / $PageLength)) + 1; //计算页数   
  8. $PageArray=array();   
  9. $Seperator = array("n",
    "r","。","!","?",";
    ",",","”","’"); //分隔符号   
  10. //echo "页数:".$PageCount." br>";   
  11. //echo "长度:".$CLength." br> br> br>";   
  12. //strpos() 函数返回字符串在
    另一个字符串中第一次出现的位置   
  13. if($CLength$PageLength)   
  14. {   
  15. echo $content;   
  16. }else{   
  17. $PageArray[0]=0;   
  18. $Pos = 0;   
  19. $i=0;   
  20. //第一页   
  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长文章分页函数最后一页   
  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)."页)n".$output;   
  63. }   
  64. echo str_replace("n"," br> 
      ",$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." 页  ";   
  71. if($page>1)   
  72. echo " a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page-1).">上一页 /a> ";   
  73. else   
  74. echo "上一页 ";   
  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).">下一页 /a> ";   
  81. else   
  82. echo " 下一页 ";   
  83. echo " /center>";   
  84. }   
  85. }   
  86. }?>  

PHP长文章分页函数的使用
 

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ?php   </span></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>
</li>
</ol>

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


声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

mPDF

mPDF

mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

EditPlus 中国語クラック版

EditPlus 中国語クラック版

サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません