Home  >  Article  >  Backend Development  >  How to read txt text file with PHP and display it in pages, _PHP tutorial

How to read txt text file with PHP and display it in pages, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:04:061006browse

How PHP reads a txt text file and displays it in pages,

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:

Copy code 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 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/966547.htmlTechArticleHow PHP reads a txt text file and displays it in pages. This example describes how PHP reads a txt text file and displays it in pages. display method. Share it with everyone for your reference. The specific implementation method is as follows:...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn