Home  >  Article  >  Backend Development  >  php有对内容进行分页的“组件”吗?

php有对内容进行分页的“组件”吗?

WBOY
WBOYOriginal
2016-06-06 20:16:281101browse

就是根据内容字数(比如说10000字)进行分页的组件?

回复内容:

就是根据内容字数(比如说10000字)进行分页的组件?

PHP 没有组件的概念,应该是 library。

可以使用 pagination 做关键词,在 github 搜索:Search pagination On Github

应该是分页class 类,封装成了一个library 类库

建议1,使用类似 [page] 的分割符进行分页:

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

建议2,按固定行数行分割:

<code>$content = '123123123123123123123
123123123123123
123123123123123
123123123123123
123123123123123
123123123123123
123123123123123
';
$lines = explode("\n", $content);
//第几页
$page = 1;
//每页显示多少行
$page_size = 2;
//当前页应该显示的行
$current_content = array_slice($lines, ($page-1)*$pagesize, $page_size);
//输出
echo implode("\n", $current_content);</code>

建议3,你想要的按 N 字分页方法:

<code>function mb_str_split($str, $length = 1, $encoding = 'utf-8') {
    if ($length </code>

PS.以上代码均手写未测试,使用时请自行适当修改

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