php-长文章分页函数
<?php function ff_page($content,$page)
{
global $expert_id;
$PageLength = 2000; //每页字数
$CLength = strlen($content);
$PageCount = floor(($CLength / $PageLength)) + 1; //计算页数
$PageArray=array();
$Seperator = array("n","r","。","!","?",";",",","”","'"); //分隔符号
//echo "页数:".$PageCount."<br>";
//echo "长度:".$CLength."<br><br><br>";
//strpos() 函数返回字符串在另一个字符串中第一次出现的位置
if($CLength<$PageLength)
{
echo $content;
}else{
$PageArray[0]=0;
$Pos = 0;
$i=0;
//第一页
for($j=0;$j<sizeof($Seperator);$j++)
{
//echo $Seperator[$j];
$Pos=strpos($content,$Seperator[$j],$PageArray[$i]+1900);
while($Pos > 0 && $Pos < ($i+1)*$PageLength && $Pos > $i*$PageLength )
{
$PageArray[$i] = $Pos ;
$Pos = strpos($Pos+$PageLength,$content,$Seperator[$j]) ;
}
if($PageArray[$i]>0)
{
$j = $j + sizeof($Seperator) + 1;
}
}
//---
for($i=1;$i<$PageCount-1;$i++){
for($j=0;$j<sizeof($Seperator);$j++)
{
//echo $Seperator[$j];
$Pos=strpos($content,$Seperator[$j],$PageArray[$i-1]+1900);
while($Pos > 0 && $Pos < ($i+1)*$PageLength && $Pos > $i*$PageLength )
{
$PageArray[$i] = $Pos ;
$Pos = strpos($Pos+$PageLength,$content,$Seperator[$j]) ;
}
if($Pag(www.111cn.net)eArray[$i]>0)
{
$j = $j + sizeof($Seperator) + 1;
}
}
}
//--最后一页
$PageArray[$PageCount-1]=$CLength;
//$page=2;
if($page==1)
{
$output=substr($content,0,$PageArray[$page-1]+2);
}
if($page>1 && $page<=$PageCount)
{
$output=substr($content,$PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]);
$output=" (上接第".($page-1)."页)n".$output;
}
echo str_replace("n","<br> ",$output);
//if($page==$PageCount)
//return $output=substr($content,$PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]);
if($PageCount>1)
{
echo "<br><br><br><center>";
echo "<font color='ff0000'>".$page."</font>/".$PageCount." 页 ";
if($page>1)
echo "<a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page-1).">上一页</a> ";
else
echo "上一页 ";
for($i=1;$i<=$PageCount;$i++)
{
echo "<a href=$PHP_SELF?expert_id=$expert_id&page_t=".$i.">[".$i."]</a> ";
}
if($page<$PageCount)
echo " <a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page+1).">下一页</a> ";
else
echo " 下一页 ";
echo "</center>";
}
}
}?>
<?php
$content1=''测试文字,尽量长一些,www.111cn.net";
$current=$_REQUEST['page_t'];
$result=ff_page($content1,$current);
echo $result;
?>
php-长文章分页函数的更多相关文章
- 使用PHP将长文章分页
如何分页 手动分页:一般在编辑内容时加入特殊分页标记,如{pages},提交后,PHP程序会根据分页符处理分页,生成不同的静态页面.这种分页方法分页准确,但是需要人工手动添加分页符,工作量大. 自动分 ...
- PHP+jQuery 长文章分页类 ( 支持 url / ajax 分页方式 )
/* ******* 环境:Apache2.2.8 ( 2.2.17 ) + PHP5.2.6 ( 5.3.3 ) + MySQL5.0.51b ( 5.5.8 ) + jQuery-1.8 **** ...
- PHP简单的长文章分页教程 附源码
PHP简单的长文章分页教程 附源码.本文将content.txt里的内容分割成3页,这样浏览起来用户体验很好. 根据分页参数ipage,获取对应文章内容 include('page.class.php ...
- ASP长文章分页的两个方法,函数
'按标识手动分页 function manualPage(str) pages=request.QueryString("page") contentstr=split(str,& ...
- tornado web高级开发项目之抽屉官网的页面登陆验证、form验证、点赞、评论、文章分页处理、发送邮箱验证码、登陆验证码、注册、发布文章、上传图片
本博文将一步步带领你实现抽屉官网的各种功能:包括登陆.注册.发送邮箱验证码.登陆验证码.页面登陆验证.发布文章.上传图片.form验证.点赞.评论.文章分页处理以及基于tornado的后端和ajax的 ...
- 简单实用的php分页函数代码
一个简单实用的php分页函数,分页导航中可以默认为空,在函数内部再设置本页URL. 代码: <?php /** * 分页 * @category 功能 * @param $totle:信息总数 ...
- php分页函数示例代码
分享一例php分页函数代码,用此函数实现分页代码很不错. 代码,php分页函数. <?php /* * Created on 2011-07-28 * Author : LKK , http:/ ...
- 本博文将一步步带领你实现抽屉官网的各种功能:包括登陆、注册、发送邮箱验证码、登陆验证码、页面登陆验证、发布文章、上传图片、form验证、点赞、评论、文章分页处理以及基于tronado的后端和ajax的前端数据处理。
本博文将一步步带领你实现抽屉官网的各种功能:包括登陆.注册.发送邮箱验证码.登陆验证码.页面登陆验证.发布文章.上传图片.form验证.点赞.评论.文章分页处理以及基于tronado的后端和ajax的 ...
- PHP 分页函数
如果如下:
随机推荐
- 面试复习(C++)之直接选择排序
#include <iostream> using namespace std; void Selection(int *a,int len) { ;i<len;i++) { int ...
- C++小项目:directx11图形程序(二):systemclass
先上代码: systemclass.h #pragma once #include"graphicsclass.h" const bool FULLSCREEN = true; c ...
- 提高开发效率的十五个Visual Studio 2010使用技巧
相信做开发的没有不重视效率的.开发C#,VB的都知道,我们很依赖VS,或者说,我们很感谢VS.能够对一个IDE产生依赖,说明这个IDE确实有它的独特之处.无容置疑,VS是一个非常强大的IDE,它支持多 ...
- 启动Mysql服务提示Can’t connect to local MySQL server through socket的解决方法
启动Mysql服务常会提示下面错误: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/ ...
- Haar-like特征
参考文献: [1]Viola P, Jones M. Rapid object detection using a boosted cascade of simple features[C]//Com ...
- centos7安装nginx
一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩. 一:安装 pcre 1.下载地址:百度云盘 http://pan.baidu.com/s/1dFusO3v ...
- Python的平凡之路(17)
一.认识jQuery jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设 ...
- Windows Phone开发需要了解的背景
在Windows Phone8.1之前,Windows Phone应用是基于Silverlight的,这些代码也不能在Windows上运行,从Windows Phone8.1开始,开发者多了一个选择, ...
- php 画图片
<?php // 使用php操作gd库做图 // 1. 创建一个画布资源 $im = imagecreatetruecolor(80, 40); // 2. 画内容 // 2.1 先位画布准备颜 ...
- join()方法之我见
JavaScript join() 方法 定义和用法 join() 方法用于把数组中的所有元素放入一个字符串. 元素是通过指定的分隔符进行分隔的. 语法 arrayObject.join(separa ...