php 快速读取txt或文本
2015-10-11 20:47
513 查看
一。读取第一行后删除
$fn = "list2.txt"; $f= fopen($fn, "r"); $line = fgets($f); ob_start(); fpassthru($f); fclose($f); file_put_contents($fn, ob_get_clean() );
其中fgets($f) 取得第一行
二、文件写入最后行file_put_contents($this->logFile, $text, FILE_APPEND | LOCK_EX);
public function export() { $text = implode("\n", array_map([$this, 'formatMessage'], $this->messages)) . "\n"; if (($fp = @fopen($this->logFile, 'a')) === false) { throw new InvalidConfigException("Unable to append to log file: {$this->logFile}"); } @flock($fp, LOCK_EX); if ($this->enableRotation) { // clear stat cache to ensure getting the real current file size and not a cached one // this may result in rotating twice when cached file size is used on subsequent calls clearstatcache(); } if ($this->enableRotation && @filesize($this->logFile) > $this->maxFileSize * 1024) { $this->rotateFiles(); @flock($fp, LOCK_UN); @fclose($fp); @file_put_contents($this->logFile, $text, FILE_APPEND | LOCK_EX); } else { @fwrite($fp, $text); @flock($fp, LOCK_UN); @fclose($fp); } if ($this->fileMode !== null) { @chmod($this->logFile, $this->fileMode); }
相关文章推荐
- 在命令行下运行php代码 和 文件
- Thinkphp学习笔记(1)
- thinkphp-上传视频操作
- PHP实现二分查找(递归与非递归)
- 在php 中使用mail函数
- phpStudy如何修改端口及WWW目录
- Rehl7 设置ntp服务,同步指定服务器时间。Ntp改为chrony
- laravel routes除了默认路由,其他的都无效 解决方案
- PHP选择性备份MySQL数据库完整函数
- 对web应用中单一入口模式的理解及php实现
- 批量下载FTP上的文件
- PHP备份MySQL数据库
- PHP打印调用堆栈信息,用于程序调试
- php中使用end方法报错
- ThinkPHP控制器分级
- Laravel 报错 :Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING)
- 【PHP】找几个例子就能快速复习PHP基础知识
- php-判断一个文件是否存在,便于删除等操作
- php mkdir函数
- php实现Mysql简易操作类