php 文章内容分页代码,是根据由编辑器插入的分页符来操作了,我们可以分出超漂亮的偏移效果的分页。文章内容分页文章内容分页
php教程 文章内容分页代码,是根据由编辑器插入的分页符来操作了,我们可以分出超漂亮的偏移效果的分页。
文章内容分页
文章内容分页
* author:陈凯
* data:2010-09-15
* 文章分页类
*/
class contentpage
{
private $content; //文章内容
private $pagesize; //每页最少字节数
private $breakflag; //分页符(可以自定义,默认为n)
private $pageurl; //url地址
private $pagevar; //分页参数
public $pagecount; //总页数
public $page; //当前页码
public $pagebreak; //每页起始位置function __construct($content = "",$pagesize = 10,$breakflag ="n",$pageurl = '',$pagevar = 'p')
{
$this->content = $content;
$this->pagesize = $pagesize;
$this->breakflag = $breakflag;
$this->pageurl = $pageurl;
$this->pagevar = $pagevar;
$this->getpages();
}//总页数,每页的起始位置和结束位置
public function getpages()
{
$contentlen = strlen($this->content); //文章总字节数
$this->pagebreak[0] = 0;
$i = 0;
$offset = $this->pagesize;
for ($k=0;$kpagesize;$k++)
{
if($offset > $contentlen)
{
$i++;
$this->pagebreak[$i] = $contentlen;
break;
}
//查找$this->pagevar出现的位置
$where = strpos($this->content,$this->breakflag,$offset);
if($where > $contentlen or intval($where) {
$i++;
$this->pagebreak[$i] = $contentlen;
break;
}
else
{
$i++;
$this->pagebreak[$i] = $where;
$offset = $where + $this->pagesize;
}
}
$this->pagecount = $i;
if(isset($_get[$this->pagevar]) && $_get[$this->pagevar] >1 && $_get[$this->pagevar] pagecount)
{
$this->page = $_get[$this->pagevar];
}
else
{
$this->page = 1;
}
}//每页内容
function getpage()
{
//截取当前页码的数据
if($this->page > 1)
{
return substr($this->content,$this->pagebreak[$this->page-1]+1,$this->pagebreak[$this->page] - $this->pagebreak[$this->page-1]);
}
else
{
return substr($this->content,$this->pagebreak[$this->page-1],$this->pagebreak[$this->page] - $this->pagebreak[$this->page-1]);
}}
//分页条
public function getpagenav()
{
if($this->page > 1)
{
$pagenav = "上一页 ";
}//输出数字页码
for($j=1;$jpagecount;$j++)
{
if($j == $this->page)
{
$pagenav .= "".$j." ";
}
else
{
$pagenav .= "".$j." ";
}
}
//下一页
if($this->page pagecount && $this->pagecount >1)
{
$pagenav .= "下一页 ";
}
return $pagenav;
}
//获取url地址
public function geturl()
{
$url = $_server['request_uri'];
$parse_url = parse_url($url);
$query_url = $parse_url['query'];
if($query_url)
{
$query_url = ereg_replace("(^|&)".$this->pagevar."=".$this->page,"",$query_url);
$url = str_replace($parse_url['query'],$query_url,$url);
if($query_url)
{
$url .= "&".$this->pagevar;
}
else
{
$url .= $this->pagevar;
}
}
else
{
$url .= "?".$this->pagevar;
}
return $url;
}
}$content = "第一页:文章内容分页阿斯顿浪费空间阿斯顿来看福建省地方吉林省福建路口附近大手拉飞机上浪费的说浪费监理费
第二页:阿斯顿房间阿双方了解啊对萨拉开发记得谁来付款将令对方空间的来福建阿里是否
第三页:欧文炯诶哦生地拉开方面来看就继续超文章内容分页滤机蓝卡
第四页:欧文日据拉萨及发动四分啊就双方的将爱是发觉是文章内容分页否了。";
$model = new contentpage($content);
echo $model->getpage(); //输出分页内容
echo $model->getpagenav(); //输出页码
?>
-->

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


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

Atom editor mac version download
The most popular open source editor

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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.