mobileka / liner

liner 是一个简单的文件读取器

1.1.0 2016-11-03 07:49 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:31:47 UTC


README

Build Status Code Climate Coverage Status

liner 是一个快速且简单的文件读取器,允许逐行读取文件。

它已经与包括超过500万行的大型文件在内的许多文件进行了测试,并证明了自己是一个快速且高效的文件读取器。

需要 PHP 5.4 或更高版本。

安装

composer require mobileka/liner:1.1.*

有时我在安装部分寻找这一行

"mobileka/liner": "1.1.*"

用法

$liner = new Liner('path/to/a/file'); // or SplFileObject instance

// Read the whole file
$liner->read();

// Only the first line
$liner->read(1);

// Only the second line
$liner->read(1, 1);

// Read 100 lines starting with the 6th line
$liner->read(100, 5);

// You can also pass a closure as a third argument to mutate the result without iterating over it
// Here's how you can read a CSV file:
$csvAsArray = $liner->read(0, 0, function($file, $line) {
    $line = trim($line);
    return explode(',', $line);
});

// A line will be ignored if modifier returns null
$anEmptyArray = $liner->read(0, 0, function($file, $line) {
    return null;
});

// almost forgot to mention that you can get the number of lines
$liner->getNumberOfLines();

// and that you can also delegate methods to SplFileObject (is it a good idea though?)
$liner->eof();
$liner->rewind();

许可证

liner 是一个开源软件,并受MIT 许可证许可。