长文章分页
- error_reporting(E_ALL ^ E_NOTICE);
- if ($_GET['page']=="") {$_GET['page']=1;}; //判断变量的值是否为空
-
- ?>
-
-
|
-
|
-
|
-
-
-
|
-
-
-
- function unhtml($content){ //定义自定义函数的名称
- $content=htmlspecialchars($content); //转换文本中的特殊字符
- $content=str_replace(chr(13),"
",$content); //替换文本中的换行符
- $content=str_replace(chr(32)," ",$content); //替换文本中的
- $content=str_replace("[_[","<",$content); //替换文本中的大于号
- $content=str_replace(")_)",">",$content); //替换文本中的小于号
- $content=str_replace("|_|"," ",$content); //替换文本中的空格
- return trim($content); //删除文本中首尾的空格
- }
- //定义一个用于截取一段字符串的函数msubstr()
- function msubstr($str,$start,$len){ //$str指的是字符串,$start指的是字符串的起始位置,$len指的是长度。
- $strlen=$start+$len; //Use $strlen to store the total length of the string (from the starting position of the string to the total length of the string)
- for($i=0;$i<$strlen;$ i++){ //Loop through the for loop statement to read the string
- if(ord(substr($str,$i,1))>0xa0){ //If the ASCII ordinal value of the first byte in the string If it is greater than 0xa0, it is expressed as a Chinese character
- $tmpstr.=substr($str,$i,2); //Take out two characters each time and assign them to the variable $tmpstr, which is equal to a Chinese character
- $i++; //The variable is incremented 1
- }else{ //If it is not a Chinese character, take out one character at a time and assign it to the variable $tmpstr
- $tmpstr.=substr($str,$i,1);}
- }
- return $tmpstr; //Output String
- }
-
- if($_GET['page']){
- $counter=file_get_contents("file/file.txt");
- $length=strlen(unhtml($counter));
- $page_count=ceil ($length/1050);
-
- $c=msubstr($counter,0,($_GET['page']-1)*1050);
- $c1=msubstr($counter,0,$_GET['page ']*1050);
- echo substr($c1,strlen($c),strlen($c1)-strlen($c));
- }
-
- ?>
-
|
-
|
-
|
-
- < table width="680" border="0" align="center" cellpadding="0" cellspacing="0">
-
-
Page: / Page |
-
Paging:
- if($_GET['page']!=1){
- echo " Home ";
- echo "Previous page  ;";
- }
- if($_GET['page']<$page_count){
- echo "Next page ";
- echo "Last page";
- }
- ?> ;
-
|
-
|