PHP 文本文章分页代码 按标记或长度(不涉及数据库)_php实例

实例代码:

复制代码 代码如下:

<?php
/**
* **********************************************************
* Read Me
* 文章分页
*
* 分页方式,可以按字数分页,按换行分页,按特殊标记分页等
* 其实实现思路是一样的,只是将其按一定规律放入一个数组
* 然后根据 url 传入的参数取得某个片段即可
* 大家完全可以写一个功能强大的函数保存起来以备不时之需
*
* 题外话:很多编辑器都有插入分页按钮,利用插入的代码可显示分页
*
* filename: page.php
* charset: UTF-8
* create date: 2012-5-16
* **********************************************************
* @author itbdw <itbudaoweng@gmail.com>
* @copyright (C) 2011-2012 itbdw
* @link http://weibo.com/itbudaoweng
*/
header('Content-Type:text/html; charset=utf-8');
?>
<?php
$title = 'Pagination Test';
//需要分页的数据
$data = <<<DATA
Hey, guys. I am here to test if it is working.
This pagination is very simple, isn't it?<!--pagination-->
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 = '<--pagination-->';
$strArr = explode($delimiter, $data);
$strNum = count($strArr);
$content = $strArr[$page];
if ($strNum > 1) {
if ($page != 0) {
$link .= '<a href="?page=0">首页</a>';
} else {
$link .= '<span>首页</span>';
}
for ($n = 0; $n < $strNum; $n++) {
if ($n == $page) {
$link .= '<span>' . ($n + 1) . '</span>';
} else {
$link .= "<a href='?page={$n}'>" . ($n + 1) . "</a>";
}
}
$link .= '';
if ($page != ($strNum - 1)) {
$link .= "<a href='?page=" . ($strNum - 1) . "'>尾页</a>";
} else {
$link .= '<span>尾页</span>';
}
}
?>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<style type="text/css">
body {
font-family: '微软雅黑';
}
.link a, span {
margin: 1px;
padding: 1px;
}
.link span {
color: #777;
}
.link a {
color: #26A2DA;
text-decoration: none;
}
</style>
<title>测试文章分页</title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<p><?php echo $content; ?></p>
<hr />
<p class="link"><?php echo $link; ?></p>
</body>
</html>

时间: 2024-08-07 10:06:19

PHP 文本文章分页代码 按标记或长度(不涉及数据库)_php实例的相关文章

asp长文章分页代码

上段时间我写了一个php的长文章分页代码用到的explode来进行分割实现的,今天我们就来讲讲asp文章分页代码以及长文章分页和asp长文章分页方法.  Function c2u(myText) Dim i c2u = "" For i = 1 to Len(myText) c2u = c2u & "&#x" & Hex(AscW(Mid(myText, i, 1))) & ";" Next End Functio

net文章分页代码

   net文章分页代码,分页功能在任一个WEB开发项目中都会用到,所以今天我们就来看看net分页代码的实现方法  private PagedDataSource pds()     {         string connstring = ConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;         //声明一个字符串,后面随时可以用         SqlConnection con = new

jQuery+FCK编辑器+PHP实现文章分页代码

在fck中插入分页符如下图 文章分页代码-jquery 长文章分页"> 分页代码   function pagebreak($content) { $content = $content; $pattern = "/<div style="page-break-after: always"><span style="display: none"> </span></div>/"; $

php 新闻文章分页代码实例教程

unction explode_content($content, $length) {  02 $i = 0;  03 $k = 1;  04 $j = 0;  05 $wn = 0;  06 $s = '';  07 $e = 1;  08 $yh = 0;  09 while ($k) {  10 $d = $content[$i];  11 if ($d !== '') {  12 if (ord($d) > 127) {  13 $j++;  14 $num = 2;  15 $i++

ASP实例代码:搞个长文章分页代码

以下为引用的内容: <%Class aspxsky_page Private Sub class_initialize End Sub  Public Function Alert(message,gourl)    message = replace(message,"'","\'")    If gourl="-1" then        Response.Write ("<script language=javasc

asp文章分页代码

'**************************************************** '函数名:StrLen '作  用:取得字符串长度(汉字为2) '参  数:str ----字符串内容 '返回值:字符串长度 '**************************************************** Function StrLen(Str)     Set rep = New regexp     rep.Global = True     rep.Ign

一个可分页的基于文本的PHP留言板源码第1/2页_php实例

小弟初学PHP,编了一个留言板程序,自我感觉良好,故厚着脸皮放了上来,请各位大哥指正.源程序如下:  <?php  //文件名:guest.php  //设定部分  $guestfile="guest";//纪录留言的文本文件  $home="index.html";//返回的主页  $imagedir="image"; //图像文件的目录  $backimage=$imagedir."/bk.gif";//背景图像 

php将url地址转化为完整的a标签链接代码(php为url地址添加a标签)_php实例

需要提取的内容如下: 复制代码 代码如下: <a href="http://baidu.com">http://baidu.com</a>这是第一个A标签,<a href="http://blog.baidu.com">成长脚印-专注于互联网发展</a>这是第二个A标签.http://www.jb51.net这是第一个需要被提取的URL地址,http://blog.baidu.com这是第二个需要被提取的URL地址'.

PHP代码保护--Zend Guard的使用详解_php实例

Zend Guard的作用,就是用编译处理的方式来保护PHP源代码免于被反编译查看.未经授权的定制修改.未经许可的使用和重新发布等.而且,它是PHP的东家Zend公司开发的,是完全为PHP量身定做的保护神. 下面,请大家就和我一起来学习使用Zend Guard,加密保护我们的PHP源代码吧. 实战:加密PHP源代码 下载:http://www.zend.com/en/products/guard/接下来让我们准备一个简单的PHP程序test.php,用来测试能否被Zend Guard保护起来.t