Home  >  Article  >  Backend Development  >  PHP long article paging function with usage method, paragraphs will not be divided, pages will be turned at the bottom_PHP tutorial

PHP long article paging function with usage method, paragraphs will not be divided, pages will be turned at the bottom_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:43:211140browse

Copy code The code is as follows:

{
global $expert_id;
$PageLength = 2000; //Number of words per page
$CLength = strlen($content);
$PageCount = floor(($CLength / $PageLength)) + 1; //Calculation Number of pages
$PageArray=array();
$Seperator = array("n","r",".","!","?",";",",","" ","'"); //delimiter

//echo "Page count: ".$PageCount."
";
//echo "Length: ".$CLength. "


";
//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=" (continued from section ".($ 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 "Previous page ";
else
echo "Previous page";

for($i =1;$i<=$PageCount;$i++)
{

echo "[".$ i."] ";
}

if($page<$PageCount)
echo " next page ";
else
echo " next page";

echo "
";
}
}

}?>

Use
to copy the code The code is as follows:

$content1=''Test text, try to be as long as possible, www.jb51.net";
$current=$_REQUEST['page_t'];
$result=ff_page($content1,$current);
echo $result;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320767.htmlTechArticleCopy the code as follows: ?php function ff_page($content,$page) { global $expert_id; $PageLength = 2000; //Number of words per page $CLength = strlen($content); $PageCount = floor(($CLength /...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn