就是根據內容字數(比如說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.以上代碼均手寫未測試,使用時請自行適當修改