php有對內容進行分頁的“組件”嗎?

來源:互聯網
上載者:User
就是根據內容字數(比如說10000字)進行分頁的組件?

回複內容:

就是根據內容字數(比如說10000字)進行分頁的組件?

PHP 沒有組件的概念,應該是 library。

可以使用 pagination 做關鍵詞,在 github 搜尋:Search pagination On Github

應該是分頁class 類,封裝成了一個library 類庫

建議1,使用類似 [page] 的分割符進行分頁:

$content = '123123123123123123123[page]123123123123123';$page = explode('[page]', $content);echo $page[0];

建議2,按固定行數行分割:

$content = '123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123';$lines = explode("\n", $content);//第幾頁$page = 1;//每頁顯示多少行$page_size = 2;//當前頁應該顯示的行$current_content = array_slice($lines, ($page-1)*$pagesize, $page_size);//輸出echo implode("\n", $current_content);

建議3,你想要的按 N 字分頁方法:

function mb_str_split($str, $length = 1, $encoding = 'utf-8') {    if ($length < 1){        return false;    }     for ($result = array(), $i = 0; $i < mb_strlen($str, $encoding); $i += $length){        $result[] = mb_substr($str, $i, $length, $encoding);    }    return $result;}$content = '123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123';$words = mb_str_split($content);//第幾頁$page = 1;//每頁顯示多少個字$page_size = 10;//當前頁應該顯示的字數$current_content = array_slice($words, ($page-1)*$pagesize, $page_size);//輸出echo implode("\n", $current_content);//PS 需要考慮空行,空格這些字

PS.以上代碼均手寫未測試,使用時請自行適當修改

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.