PHP code example of locr-company / csv-reader

1. Go to this page and download the library: Download locr-company/csv-reader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

locr-company / csv-reader example snippets




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";
});
bash
git clone [email protected]:locr-company/php-csv-reader.git
cd php-csv-reader && composer install