Copy CodeThe code is as follows:
{
Global $expert _id;
$PageLength = 2000; Words per page
$CLength = strlen ($content);
$PageCount = Floor (($CLength/$PageLength) + 1; Count pages
$PageArray =array ();
$Seperator = Array ("\ n", "\ R", ". ","! ","? ",";",",","”","'"); Delimited symbols
echo "pages:". $PageCount. "
";
echo "Length:". $CLength. "
";
The Strpos () function returns the position of 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 {
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 {
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 = "(prev.)." ($page-1). " page) \ n ". $output;
}
echo str_replace ("\ n", "
", $output);
if ($page = = $PageCount)
Return $output =substr ($content, $PageArray [$page -2]+2, $PageArray [$page -1]-$PageArray [$page-2]);
if ($PageCount >1)
{
echo "
";
echo "". $page. " /". $PageCount." Page ";
if ($page >1)
echo "Prev";
Else
echo "Prev";
for ($i =1; $i <= $PageCount; $i + +)
{
echo "[". $i. "]";
}
if ($page < $PageCount)
echo "Next page";
Else
echo "Next page";
echo " ";
}
}
}?>
Use
Copy the Code code as follows:
$c
$current =$_request[' page_t '];
$result =ff_page ($content 1, $current);
echo $result;
?>
The above describes the use of the lookup function, PHP long article paging function with the use of the method, will not split the paragraph, page to the bottom, including the use of the lookup function of the content, I hope that the PHP tutorial interested in a friend helpful.