locr-company/csv-reader

用于读取csv文件的类。

1.0.2 2023-10-13 15:10 UTC

This package is auto-updated.

Last update: 2024-09-30 06:47:53 UTC


README

php codecov github_workflow_status Quality Gate Status github_tag packagist

1. 安装

composer require locr-company/csv-reader

2. 使用方法

以下是文档

<?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. 开发

克隆仓库

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