matrixpro / csv-reader
Reads CSV files.
dev-master
2019-03-06 00:46 UTC
Requires
- php: >=5.6.4
- matrixpro/csv-delimiter-finder: dev-master
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2025-05-06 15:34:03 UTC
README
Reads CSV files and returns an array containing all or some of the CSV rows. For large CSV files you may specify how many rows to work with at a time and where to start via the file pointer position. Compatible with large CSV datasets (tested on 4gb+ files).
Install via composer:
composer require matrixpro/csv-reader
Usage
Pass a CSV file handle to the reader and use the getRows() method.
$handle = fopen('path/to/file.csv', "r"); $reader = new CsvReader($handle); $rows = $reader->getRows();
Get First Five Rows
Optionally save the position so you can process some rows and pick it up again later.
$first_five_rows = $reader->getRows(5); $csv_position = $reader->getPosition();
Get Next Five Rows
Use the position saved earlier to continue processing the file.
$second_five_rows = $reader->getRows(5, $csv_position);