Long article pagination
- Error_reporting (E_ALL ^ E_NOTICE );
- If ($ _ GET ['Page'] = "") {$ _ GET ['Page'] = 1 ;}; // determines whether the variable value is null.
- ?>
-
-
-
-
-
-
-
-
-
-
-
|
|
|
|
-
-
-
-
-
- Function unhtml ($ content) {// define the name of the custom function
- $ Content = htmlspecialchars ($ content); // Convert Special characters in text
- $ Content = str_replace (chr (13 ),"
", $ Content); // replace the line break in the text - $ Content = str_replace (chr (32), "", $ content); // replace
- $ Content = str_replace ("[_ [", "<", $ content); // replace the greater than sign in the text
- $ Content = str_replace (") _)", ">", $ content); // replace the minor sign in the text
- $ Content = str_replace ("| _ |", "", $ content); // replace spaces in the text
- Return trim ($ content); // delete spaces at the beginning and end of the text
- }
- // Define a function msubstr () used to intercept a string ()
- Function msubstr ($ str, $ start, $ len) {// $ str indicates the string, $ start indicates the start position of the string, and $ len indicates the length.
- $ 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 ++) {// read strings cyclically using the for statement
- 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
- $ Tmpstr. = substr ($ str, $ I, 2); // Extract two characters each time and assign them to the variable $ tmpstr, which is equal to one Chinese character.
- $ I ++; // variable auto-Increment 1
- } Else {// if it is not a Chinese character, a character is taken out each time and assigned 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 ));
- }
-
- ?>
-
|
|
|
-
-
-
-
Page: / Page |
Paging:- If ($ _ GET ['Page']! = 1 ){
- Echo "homepage ";
- Echo "previous page ";
- }
- If ($ _ GET ['Page'] <$ page_count ){
- Echo "next page ";
- Echo "last page ";
- }
- ?>
-
|
|