时间:2021-07-01 10:21:17 帮助过:37人阅读
php对文本文件进行分页功能简单实现
Paging php// 中文字符处理function m_substr($str, $start, $length){ $str_length = $start + $length; // 获取截取总长度 $tmp_str = ""; for($i=0;$i<$str_length;$i++){ if(ord(substr($str, $i, 1)) == 0x0a){ $tmp_str .= "
"; } if(ord(substr($str, $i, 1))>0xa0){ $tmp_str .= substr($str, $i, 2); $i++; }else{ $tmp_str .= substr($str, $i, 1); } } return $tmp_str;}// 传参处理if(isset($_GET['page'])){ $page = $_GET['page'];}else{ $page = 1;}$counter = file_get_contents("example.txt");$length = strlen($counter);$page_count = ceil($length/400);$pre_str = m_substr($counter, 0, ($page-1)*400);$now_str = m_substr($counter, 0, $page*400);echo substr($now_str, strlen($pre_str), strlen($now_str)-strlen($pre_str));echo "
";echo "当前页".$page."/".$page_count;echo "Index";if($page>1){ echo "$page-1)."'>Pre";}if($page<$page_count){ echo "$page+1).">Next";}echo "$page_count>End";?>