博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php 倒序读取txt 文件中最后几行的内容,带分页
阅读量:7014 次
发布时间:2019-06-28

本文共 793 字,大约阅读时间需要 2 分钟。

  hot3.png

// $filename: 文件名	// $start: 从倒数第几行开始	// $lines: 读取几行	function read_backward_line($filename, $start, $lines){	    $lines++;	    $offset = -1;	    $c = '';	    $read = '';	    $i = 0;	    $fp = @fopen($filename, "r");			    $tmpStart = 0;	    while( $lines && fseek($fp, $offset, SEEK_END) >= 0 ) {	        	        $c = fgetc($fp);	        if($c == "\n" || $c == "\r"){	            if(++$tmpStart >= $start)	                $lines--;	        }			        if($tmpStart >= $start)	            $read .= $c;	        $offset--;	    }		    $read = trim($read);			    $read = array_reverse(explode("\n",strrev($read)));	    foreach($read as $key => $value) {	        if (empty($value)) {	            unset($read[$key]);	        }	    }	    return $read;	}

转载于:https://my.oschina.net/kacper/blog/185602

你可能感兴趣的文章
webpack由浅入深——(webapck简易版)
查看>>
RxSwift(伪)实战 组内分享
查看>>
2 - 建立 Django 博客应用
查看>>
【iOS报错】“this class is not key value coding-compliant for the key userPhoneNum”给字典设置键值对的时候报错...
查看>>
UI技术总结--性能优化
查看>>
Android NDK JNI 开发之旅01 环境搭建入门篇
查看>>
Javascript之迭代器模式
查看>>
Flutter花式玩转TextField,写一个验证码输入框超简单!
查看>>
RxJava应用:实现七牛云多图上传
查看>>
Tmux入门教程
查看>>
智能直播审核方案:视频云智能业务截帧策略
查看>>
亲历者说:Kubernetes API 与 Operator,不为人知的开发者战争
查看>>
[ARKit]10-3D模型怎么制作,哪里寻找,如何使用?
查看>>
Kotlin结合DataBinding简单封装一个RecyclerView的Adapter
查看>>
Android爬坑之旅之不易发现的BUG
查看>>
数值计算 插值与拟合
查看>>
支付与签名原串的那些事,但选择排序生成签名原串
查看>>
koa2开发微信公众号: 不定期推送最新币圈消息
查看>>
小tips:JS中this操作执行像(object.getName = object.getName)()操作改变了this
查看>>
为什么国外的 App 很少会有开屏广告?
查看>>