a.php how to read txt text files and display them in pagination

Source: Internet
Author: User
Tags ord

How php reads txt text files and displays them in pagination

Tomrobert font: [Increase decrease] Type: Reprint time: 2015-03-11 I want to comment

This article mainly introduces the PHP read txt text file and pagination display method, involving PHP operation file skills, with a certain reference value, the need for friends can refer to the next

The example in this article describes how PHP reads txt text files and displays them in pagination. Share to everyone for your reference. The implementation method is as follows:

Copy CodeThe code is as follows: <?php
Session_Start ();
if (empty ($page)) {$page = 1;}
if (Isset ($_get[' page ') ==true) {$page =$_get[' page '];}
?>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>read result</title>
<style type= "Text/css" >
<!--
. STYLE1 {font-size:12px}
. STYLE2 {font-size:18px}
-
</style>
<body>
<table width= "100%" bgcolor= "#CCCCCC" >
<tr>
&LT;TD >
<?php
if ($page) {
$counter =file_get_contents ("Example.txt"); Read TXT file contents 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. = ' <br/> ';
}
if (Ord (substr ($str, $i, 1)) >0xa0) {
$tmpstr. =substr ($str, $i, 2);
$i + +;
}
else{
$tmpstr. =substr ($str, $i, 1); }
}
return $tmpstr;
}
------------Intercept Chinese strings---------
$c =msubstr ($counter, 0, ($page-1) *5000);
$c 1=msubstr ($counter, 0, $page *5000);
Echo substr ($c 1,strlen ($c), strlen ($c 1)-strlen ($c));
}?>
</td>
</tr>
</table>
<table width= "100%" bgcolor= "#cccccc" >
<tr>
&LT;TD width= "42%" align= "center" valign= "middle" ><span class= "STYLE1" > <?php echo $page;? >/<?php echo $page _count;? > Page </span></td>
&LT;TD width= "58%" height= "" align= "left" valign= "Middle" >
<span class= "STYLE1" >
<?php
echo "<a href=m.php?page=1> home </a>";
if ($page!=1) {
echo "<a href=m.php?page=". ($page-1). " > Prev </a> ";
}
if ($page < $page _count) {
echo "<a href=m.php?page=". ($page + 1). " > Next </a> ";
}
echo "<a href=m.php?page=". $page _count. " > End </a> ";
?>
</span> </td>
</tr>
</table>
</body>
Source: http://www.jb51.net/article/62004.htm

a.php how to read txt text files and display them in pagination

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.