PHP reads txt files and displays them by page. PHP: how to read txt files and display them by page. This article mainly introduces how PHP reads txt files and displays them by page. it involves php file operations, methods for reading txt text files from PHP and displaying them by page
This article mainly introduces how PHP reads txt text files and displays them by page. it involves php file operations and has some reference value. For more information, see
This example describes how PHP reads txt text files and displays them by page. Share it with you for your reference. The specific implementation method is as follows:
The code is as follows:
Session_start ();
If (empty ($ page) {$ page = 1 ;}
If (isset ($ _ GET ['Page']) = TRUE) {$ page = $ _ GET ['Page'];}
?>
Read Result
If ($ page ){ $ Counter = file_get_contents ("example.txt"); // read the contents of the txt file to $ counter $ Length = strlen ($ counter ); $ Page_count = ceil ($ length/5000 ); Function msubstr ($ str, $ start, $ len ){ $ Strlength = $ start + $ len; $ Tmpstr = ""; For ($ I = 0; $ I <$ strlength; $ I ++ ){ If (ord (substr ($ str, $ I, 1) = 0x0a ){ $ Tmpstr. =' '; } If (ord (substr ($ str, $ I, 1)> 0xa0 ){ $ Tmpstr. = substr ($ str, $ I, 2 ); $ I ++; } Else { $ Tmpstr. = substr ($ str, $ I, 1 );} } Return $ tmpstr; } // ------------ Intercept a Chinese string --------- $ C = msubstr ($ counter, 0, ($ page-1) * 5000 ); $ C1 = msubstr ($ counter, 0, $ page * 5000 ); Echo substr ($ c1, strlen ($ c), strlen ($ c1)-strlen ($ c )); }?>
|
/ Page |
Echo "homepage "; If ($ page! = 1 ){ Echo "previous page "; } If ($ page <$ page_count ){ Echo "next page "; } Echo "last page "; ?> |
I hope this article will help you with php programming.
This article describes how to use PHP to read txt text files and display them by page. it involves php file operations and provides reference prices...