/*文章分页代码*/
$fp=fopen('txt.txt','r');
while (!feof($fp)){
$content.=fgets($fp);
}
$c_page="";
if(isset($_GET['page'])) $c_page=$_GET['page'];
$listlen=100; //分页显示字符数
$conlen=strlen($content); //内容长度
$j=0;
$listat[0]=0;
$lookat=0;
for ($i=1;$i
//echo $conlen/$listlen;
if($lookat
$lookat=$listlen;
if($lookat>$conlen){
$j++;
$listat[$j]=$conlen;
break;
}
$endat=strpos($content,"\n",$lookat);
if($endat>$conlen-$listlen/5 or intval($endat)<1){
$j++;
$listat[$j]=$conlen;
break;
}else {
$j++;
$listat[$j]=$endat;
$lookat=$endat+$listlen;
}
}
//print page
$pagenum=$j; //总页数
$page=intval($c_page);
if(empty($page) or $page<1 or $page>$pagenum) $page=1;
if($pagenum >1)
for ($i=1;$i
echo " {$i} ";
}
echo "
";
$stag=$page-1;
$startb=$listat[$stag];
if($startb>0) //去除首个换行
$startb=$startb+1;
$cont=substr($content,$startb,$listat[$page]-$startb);
echo "
文章内容:
";
if($page>1)
echo "[接上页] ";
echo $cont;
?>