PHP Long article paging function

Source: Internet
Author: User

<?php function Ff_page ($content, $page)
{
Global $expert _id;
$PageLength = 2000; Number of words per page
$CLength = strlen ($content);
$PageCount = Floor (($CLength/$PageLength)) + 1; Count pages
$PageArray =array ();
$Seperator = Array ("n", "R", ".) ","! ","? ",";",",","”","'"); Separator symbol
echo "page:". $PageCount. " <br> ";
echo "Length:". $CLength. " <br><br><br> ";
The Strpos () function returns the first occurrence of a string in another string
if ($CLength < $PageLength)
{
Echo $content;
}else{
$PageArray [0]=0;
$Pos = 0;
$i = 0;
First page
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 ($PageArray [$i]>0)
{
$j = $j + sizeof ($Seperator) + 1;
}
}
}

--Last page
$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 = "(upper part). ($page-1). " page) 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." Page ";
if ($page >1)
echo "<a href= $PHP _self?expert_id= $expert _id&page_t=". ($page-1). " > Prev </a> ";
Else
echo "Prev";
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). " > next page </a> ";
Else
echo "Next page";
echo "</center>";
}
}
}?>

<?php
$content 1 = ' Test text, as long as possible, www.111cn.net ';
$current =$_request[' page_t '];
$result =ff_page ($content 1, $current);
echo $result;
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.