Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-13 10:03:56
Original
1171 people have browsed it

How to read txt text files with PHP and display them in pages

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:

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/966929.htmlTechArticleHow PHP reads txt text files and displays them in pages. This article mainly introduces how PHP reads txt text files and displays them in pages. The paging display method involves the skills of operating files in PHP and has certain reference value...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template