Long article page-php Tutorial

Source: Internet
Author: User
Long article pagination
Long article pagination

  1. Error_reporting (E_ALL ^ E_NOTICE );
  2. If ($ _ GET ['Page'] = "") {$ _ GET ['Page'] = 1 ;}; // determines whether the variable value is null.
  3. ?>
  4.    
     
  5. Function unhtml ($ content) {// define the name of the custom function
  6. $ Content = htmlspecialchars ($ content); // Convert Special characters in text
  7. $ Content = str_replace (chr (13 ),"
    ", $ Content); // replace the line break in the text
  8. $ Content = str_replace (chr (32), "", $ content); // replace
  9. $ Content = str_replace ("[_ [", "<", $ content); // replace the greater than sign in the text
  10. $ Content = str_replace (") _)", ">", $ content); // replace the minor sign in the text
  11. $ Content = str_replace ("| _ |", "", $ content); // replace spaces in the text
  12. Return trim ($ content); // delete spaces at the beginning and end of the text
  13. }
  14. // Define a function msubstr () used to intercept a string ()
  15. Function msubstr ($ str, $ start, $ len) {// $ str indicates the string, $ start indicates the start position of the string, and $ len indicates the length.
  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 ++) {// read strings cyclically using the for statement
  18. If (ord (substr ($ str, $ I, 1)> 0xa0) {// if the ASCII order value of the first byte in the string is greater than 0xa0, it is expressed as a Chinese character
  19. $ Tmpstr. = substr ($ str, $ I, 2); // Extract two characters each time and assign them to the variable $ tmpstr, which is equal to one Chinese character.
  20. $ I ++; // variable auto-Increment 1
  21. } Else {// if it is not a Chinese character, a character is taken out each time and assigned 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. Page: / Page Paging:
  37. If ($ _ GET ['Page']! = 1 ){
  38. Echo "homepage ";
  39. Echo "previous page ";
  40. }
  41. If ($ _ GET ['Page'] <$ page_count ){
  42. Echo "next page ";
  43. Echo "last page ";
  44. }
  45. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.