This article mainly introduces the method of reading txt text files with PHP and displaying them in pages, involving techniques for operating files in PHP , has certain reference value, friends in need can refer to it
The example in this article describes how PHP reads a txt text file and displays it in pages. Share it with everyone for your reference. The specific implementation method is as follows:
The code is as follows:
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 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 be helpful to everyone’s PHP programming design.