澳门新葡萄京娱乐场PHP 长文章分页函数

?$pieces = explode(HR,
$news[‘content’]);//以HR水平线分隔$page=count($pieces);if(empty($move)){$move=0;}else{$move=$move;}echo
$pieces[$move].brbr;if($page1){echo a href=$PHP_SELF?id=$idmove=0FONT
face=webdings9/FONT/a;$up=$move-1;if($move0){echo a
href=$PHP_SELF?id=$idmove=$upfont face=webdings7/font/a;}$x=$move+1;for
($i=1,$jump=$i-1;$i= $move;$i++,$jump++)echo a
href=$PHP_SELF?id=.$id.move=.$jump.B.$i ./B/a;echo span
class=red1B.$x./B/span;for
($i=$move+2,$jump=$i-1;$i=$page;$i++,$jump++)echo a
href=$PHP_SELF?id=.$id.move=.$jump.B.$i
./B/a;$down=$move+1;if($page0$down$page){echo a
href=$PHP_SELF?id=$idmove=$downFONT
face=webdings8/FONT/a;}$end=$page-1;echo a
href=$PHP_SELF?id=$idmove=$endFONT
face=webdings:/FONT/a;$curent=$move+1;?

最后一步就是显示了。 
下面这个程序要通过参数来调用。 
比如php.php?jpg=jpg 
后面的jpg是表格名。记住一定要的呀,不然就不能运行了,会显示程序出错。 
大家可以把下面这个程序改一下。这样就可以更加美观了。 
以下是源程序: 
<html> 
<head><title>显示</title> 
</head> 
<body> 
<? 
mysql_connect(“localhost”,”用户名”,”密码”) or die(“无法联接数据库!”); 
$query=”SELECT id,url,mess,fromx,url1,mess1,fromx1,url2,mess2,fromx2,url3,mess3,fromx3 from $jpg ” ; 
$result=mysql_db_query(“elong”,$query); //执行查询 
$num=mysql_numrows($result); 
$page=round($page); 
$pagesize=4; 
if ($page==0){ 
$page=1;} 
else{ 
$page=$page;} 
$pagecount=($num)/$pagesize; 
$pagecount=ceil($pagecount); 
?> 
<?if ($page!=1 and $num!=0){ 
printf(“<a href=”%s?page=%s&jpg=$jpg”>首页</a>”,$PHP_SELF,1); 
printf(“<a href=”%s?page=%s&jpg=$jpg”> 前页</a>”,$PHP_SELF,$page-1); 
}else{ 
?> 首页 前页 <? 

?> 
</font>  
<?if ($page!=$pagecount and $num!=0){ 
printf(“<a href=”%s?page=%s&jpg=$jpg”> 后页</a>”,$PHP_SELF,$page+1); 
printf(“<a href=”%s?page=%s&jpg=$jpg”> 尾页</a>”,$PHP_SELF,$pagecount); 
}else{?> 后页 尾页 <?}?>页次:<strong><?echo $page?></strong>/<strong><?echo $pagecount?></strong>页 
</span></td> 
<? 
if ($num<>0){ 
$pp=0; 
for($ipage=0;$ipage<$pagesize;$ipage++){ 
$i=($page-1)*$pagesize+$ipage; 
if($i < $num) { 
$id=mysql_result($result,$i,”id”); 
$url=mysql_result($result,$i,”url”); 
$mess=mysql_result($result,$i,”mess”); 
$fromx=mysql_result($result,$i,”fromx”); 
澳门新葡萄京娱乐场 ,$url1=mysql_result($result,$i,”url1″); 
$mess1=mysql_result($result,$i,”mess1″); 
$fromx1=mysql_result($result,$i,”fromx1″); 
$url2=mysql_result($result,$i,”url2″); 
$mess2=mysql_result($result,$i,”mess2″); 
$fromx2=mysql_result($result,$i,”fromx2″); 
$url3=mysql_result($result,$i,”url3″); 
$mess3=mysql_result($result,$i,”mess3″); 
$fromx3=mysql_result($result,$i,”fromx3″); 
$pp=$pp+1; 
       ?> 
<table width=”668″ border=”2″ cellspacing=”0″ cellpadding=”0″ align=”center” bordercolor=”#FFFFFF”> 
<tr> 
<td width=”167″ height=”127″> <a href=”<?echo $url?>” target=”_blank”><IMG border=0 src=”<?echo $mess?>” width=”160″ height=”120″ border=”4″></td> 
<td width=”167″ height=”127″><a href=”<?echo $url1?>” target=”_blank”><IMG border=0 src=”<?echo $mess1?>” width=”160″ height=”120″ border=”4″></td> 
<td width=”167″ height=”127″><a href=”<?echo $url2?>” target=”_blank”><IMG border=0 src=”<?echo $mess2?>” width=”160″ height=”120″ border=”4″></td> 
<td width=”167″ height=”127″><a href=”<?echo $url3?>” target=”_blank”><IMG border=0 src=”<?echo $mess3?>” width=”160″ height=”120″ border=”4″></td> 
</tr> 
</table> 
<? 



?> 
  <td nowrap align=center> <span class=smallFont><span class=titleFont>分页</span> 
     <font color=darkgray> <?if ($page!=1 and $num!=0){ 
printf(“<a href=”%s?page=%s&jpg=$jpg”>首页</a>”,$PHP_SELF,1); 
printf(“<a href=”%s?page=%s&jpg=$jpg”> 前页</a>”,$PHP_SELF,$page-1); 
}else{ 
?> 首页 前页 <?}?> </font> <?if ($page!=$pagecount and $num!=0){ 
printf(“<a href=”%s?page=%s&jpg=$jpg”> 后页</a>”,$PHP_SELF,$page+1); 
printf(“<a href=”%s?page=%s&jpg=$jpg”> 尾页</a>”,$PHP_SELF,$pagecount); 
}else{?> 后页 尾页 <?}?>页次:<strong><?echo $page?></strong>/<strong><?echo $pagecount?></strong>页 
</span></td> 
 </TABLE></DIV></CENTER> 
</BODY></HTML> 

<?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($PageArray[$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;
?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注