locr-company/csv-reader

A class for reading csv-files.

1.0.3 2024-11-22 12:50 UTC

This package is auto-updated.

Last update: 2024-12-23 06:15:21 UTC


README

php github_workflow_status codecov Quality Gate Status github_tag packagist

1. Installation

composer require locr-company/csv-reader

2. How to use

Here are the Docs.

<?php

use Locr\Lib\CsvReader;

$csvReader = new CsvReader();
$csvReader->loadFile('file.csv');
$csvReader->setFirstLineIsHeader(true); // if the first line of the csv-file has column informations

// read all rows at once
$rows = $csvReader->readDataset();
foreach ($rows as $row) {
    print $row['column1'] . '|' . $row['column2'] . "\n";
}

// read rows one by one, if you expect a very large csv-file
$csvReader->readDatasetsCallback(function (array $row, int $lineNumber) {
    print $row['column1'] . '|' . $row['column2'] . "\n";
});

3. Development

Clone the repository

git clone git@github.com:locr-company/php-csv-reader.git
cd php-csv-reader && composer install