alva/csv-each

Line by line read csv file

1.0 2018-12-24 00:04 UTC

This package is auto-updated.

Last update: 2024-10-29 05:28:34 UTC


README

Version License Downloads StyleCI

Features:

  • PHP >=7.1
  • stable
  • fast Minimal overhead

Install

composer require alva/csv-each:1.*
{
    "require": {
        "alva/csv-each": "1.*"
    }
}

Examples

Line by line reading

use Alva\CsvEach\Iterate;

foreach ((new Iterate($pathToFile))->each(Iterate::TYPE_TEXT) as $lineNumber => $line) {
    echo '[' . $lineNumber . '] ' . $line . PHP_EOL;
}

Line by line reading and return columns

use Alva\CsvEach\Iterate;

foreach ((new Iterate($pathToFile))->setDelimiter(',')->each(Iterate::TYPE_ARRAY) as $lineNumber => $line) {
    echo '[' . $lineNumber . '] ' . PHP_EOL;
    print_r($line);
}

Byte read

use Alva\CsvEach\Iterate;

foreach ((new Iterate($pathToFile))->each(Iterate::TYPE_BINARY, 5) as $lineNumber => $line) {
    echo '[' . $lineNumber . '] ' . $line . PHP_EOL;
}

Tests

./vendor/bin/phpunit