<?php header('content-type:text/html;charset=utf8'); if(isset($_GET['page'])){ $page=$_GET['page']; }else{ $page=1; } //Define a function msubstr() for intercepting a string function msubstr($str,$start,$len){ //$str refers to the string, $start refers to the starting position of the string, and $len refers to the length. $tmpstr=""; $strlen=$start+$len; //Use $strlen to store the total length of the string (from the start of the string to the total length of the string) for($i=0;$i<$strlen;$i++){ //Through the for loop statement, read the string in a loop if(ord(substr($str,$i,1))>0xa0){ //If the ASCII ordinal value of the first byte in the string is greater than 0xa0, it means Chinese characters $tmpstr.=substr($str,$i,2); //Take out two characters each time and assign them to the variable $tmpstr, which is equal to one Chinese character $i++; //The variable is incremented by 1 }else{ //If it is not a Chinese character, take out one character each time and assign it to the variable $tmpstr $tmpstr.=substr($str,$i,1);} } return $tmpstr; //output string } ?> <div id="synopsis"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="20"> </td> </tr> <tr> <td> <?php if($page){ $counter=file_get_contents("test.txt"); $length=strlen($counter); //Read the super-long text data and realize the paging display of the data in the super-long text $page_count=ceil($length/2048); //Calculate the number of pages, round up to an integer $c=msubstr($counter,0,($page-1)*2048); $c1=msubstr($counter,0,$page*2048); echo substr($c1,strlen($c),strlen($c1)-strlen($c)); }?> </td> </tr> <tr> <td> <table> <tr> <td> <span> 页次:<?php echo $page;?> / <?php echo $page_count;?> 页 </span> </td> <td> <span> pagination: <?php if($page!=1){ ?> <a href="#" onclick='return artpagination("test.php?page=1")'>首页</a> <a href="#" onclick='return artpagination("test.php?&page=<?php echo $page-1;?>")'>上一页</a> <?php } if($page<$page_count){ ?> <a href="#" onclick='return artpagination("test.php?page=<?php echo $page+1;?>")'>下一页</a> <a href="#" onclick='return artpagination("test.php?page=<?php echo $page_count;?>")'>尾页</a> <?php } ?> </span> </td> </tr> </table> </td> </tr> </table> </div> <script> //Create an asynchronous HTTP request using the XMLHttpRequest object function artpagination(url){ //Create a custom function to get the passed parameters xmlHttp=new XMLHttpRequest(); xmlHttp.open('get',url,true); //According to the passed parameters, through the get method, execute another file that implements the paging function xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4 && xmlHttp.status == 200){ //Return the result to the div tag synopsis document.getElementById("synopsis").innerHTML = xmlHttp.responseText; } } xmlHttp.send(null); } </script>