Home >Backend Development >PHP Tutorial >Long article pagination

Long article pagination

WBOY
WBOYOriginal
2016-07-25 08:47:57810browse
  • 长文章分页
    1. error_reporting(E_ALL ^ E_NOTICE);
    2. if ($_GET['page']=="") {$_GET['page']=1;}; //判断变量的值是否为空
    3. ?>
    4.    
       
    5. function unhtml($content){ //定义自定义函数的名称
    6. $content=htmlspecialchars($content); //转换文本中的特殊字符
    7. $content=str_replace(chr(13),"
      ",$content); //替换文本中的换行符
    8. $content=str_replace(chr(32)," ",$content); //替换文本中的 
    9. $content=str_replace("[_[","<",$content); //替换文本中的大于号
    10. $content=str_replace(")_)",">",$content); //替换文本中的小于号
    11. $content=str_replace("|_|"," ",$content); //替换文本中的空格
    12. return trim($content); //删除文本中首尾的空格
    13. }
    14. //定义一个用于截取一段字符串的函数msubstr()
    15. function msubstr($str,$start,$len){ //$str指的是字符串,$start指的是字符串的起始位置,$len指的是长度。
    16. $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)
    17. for($i=0;$i<$strlen;$ i++){ //Loop through the for loop statement to read the string
    18. 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
    19. $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
    20. $i++; //The variable is incremented 1
    21. }else{ //If it is not a Chinese character, take out one character at a time and assign it to the variable $tmpstr
    22. $tmpstr.=substr($str,$i,1);}
    23. }
    24. return $tmpstr; //Output String
    25. }
    26. if($_GET['page']){
    27. $counter=file_get_contents("file/file.txt");
    28. $length=strlen(unhtml($counter));
    29. $page_count=ceil ($length/1050);
    30. $c=msubstr($counter,0,($_GET['page']-1)*1050);
    31. $c1=msubstr($counter,0,$_GET['page ']*1050);
    32. echo substr($c1,strlen($c),strlen($c1)-strlen($c));
    33. }
    34. ?>
    35.  
    36. < 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";
  • }
  • ?> ;
  • Copy code


    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
    Previous article:Controller base classNext article:Controller base class

    Related articles

    See more