PHP 文本文章分页代码 按标记或长度(不涉及数据库)
实例代码:
复制代码 代码如下:
/**
* **********************************************************
* Read Me
* 文章分页
*
* 分页方式,可以按字数分页,按换行分页,按特殊标记分页等
* 其实实现思路是一样的,只是将其按一定规律放入一个数组
* 然后根据 url 传入的参数取得某个片段即可
* 大家完全可以写一个功能强大的函数保存起来以备不时之需
*
* 题外话:很多编辑器都有插入分页按钮,利用插入的代码可显示分页
*
* filename: page.php
* charset: UTF-8
* create date: 2012-5-16
* **********************************************************
* @author itbdw
* @copyright (C) 2011-2012 itbdw
* @link http://weibo.com/itbudaoweng
*/
header('Content-Type:text/html; charset=utf-8');
?>
$title = 'Pagination Test';
//需要分页的数据
$data = Hey, guys. I am here to test if it is working.
This pagination is very simple, isn't it?
And I tried to use different method to page it.
Can you see it?
DATA;
//当前文章页
$page = 0;
//初始文章长度
$length = 0;
//分页长度
$perpage = 160;
//显示在页面的代码
$link = '';
//分割后的数组
$strArr = array();
$page = isset($_GET['page']) ? intval($_GET['page']) : 0;
$length = strlen($data);
//按字数分割
// $str = str_split($data, $perpage);
//按字符分割
$delimiter = "\n";
// $delimiter = '';
$strArr = explode($delimiter, $data);
$strNum = count($strArr);
$content = $strArr[$page];
if ($strNum > 1) {
if ($page != 0) {
$link .= '首页';
} else {
$link .= '首页';
}
for ($n = 0; $n if ($n == $page) {
$link .= '' . ($n + 1) . '';
} else {
$link .= "" . ($n + 1) . "";
}
}
$link .= '';
if ($page != ($strNum - 1)) {
$link .= "尾页";
} else {
$link .= '尾页';
}
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.