We are going to write a native article content pagination program. The principle is very simple. When editing, we insert page breaks in the editor, and then when displaying, we can directly use explode to paginate. Of course, there are more advanced ones. It is to save different records in pages, and then generate them again which is relatively complicated.
Split the text according to a certain string. After splitting, perform array indexing according to the page number and output the value of the array corresponding to the current page number. It seems confusing enough. Here is an example:
The code is as follows
代码如下 |
复制代码 |
$str = "asd啊是大叔大叔asd杀毒发[NextPage]生的啊师傅 asd 啊师傅asd a速度发啥地方";
//接收页码(如果不存在就为1)
$page = $_REQUEST['page'] ? $_REQUEST['page'] : 1;
//通过分割符分割内容
$arr = explode("[NextPage]",$str);
//如果分割出来的数组大小为1即未进行分页
if(count($arr)==1){
echo $str;
}else{
//按页码输出相应的内容
echo $arr[$page-1];
//分页页码
for($i=1;$i<=count($arr);$i++){
if($page == $i){//当前页
echo "".$i." ";
}else{
echo "".$i." ";
}
}
}
?>
|
|
Copy code |
|
$str = "asd
isUncle, uncle asd antivirus hair [NextPage], ah master
asd ah master asd a speed hair place";
//Receive page number (1 if it does not exist)
$page = $_REQUEST['page'] ? $_REQUEST['page'] : 1;
//Split content by delimiter
$arr = explode("[NextPage]",$str);
//If the size of the divided array is 1, no paging is performed
if(count($arr)==1){
echo $str;
}else{
//Output the corresponding content according to the page number
echo $arr[$page-1];
//Page number
for($i=1;$i<=count($arr);$i++){
if($page == $i){//Current page
echo "
".$i." ";
}else{
echo "
".$i." ";
}
}
}
?>
http://www.bkjia.com/PHPjc/631517.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/631517.htmlWe are going to write a native article content paging program. The principle is very simple, that is, when editing, we are in the editor Insert page breaks, and then we can directly use explode to paginate when displaying...