keboola/csv
Composer 安装命令:
composer require keboola/csv
包简介
Keboola CSV reader and writer
README 文档
README
The library provides a simple reader and writer for CSV files according to RFC4180.
The library is licensed under the MIT license. The library provides
classes CsvReader and CsvWriter for reading and writing CSV files. The classes are designed to be immutable
and minimalistic.
Usage
Read CSV
$csvFile = new Keboola\Csv\CsvReader(__DIR__ . '/_data/test-input.csv'); foreach($csvFile as $row) { var_dump($row); }
Skip lines
Skip the first line:
$csvFile = new \Keboola\Csv\CsvFile( $fileName, CsvFile::DEFAULT_DELIMITER, CsvFile::DEFAULT_ENCLOSURE, CsvFile::DEFAULT_ESCAPED_BY, 1 ) foreach($csvFile as $row) { var_dump($row); }
Write CSV
$csvFile = new Keboola\Csv\CsvWriter(__DIR__ . '/_data/test-output.csv'); $rows = [ [ 'col1', 'col2', ], [ 'first column', 'second column', ], ]; foreach ($rows as $row) { $csvFile->writeRow($row); }
Append to CSV
$fileName = __DIR__ . '/_data/test-output.csv'; $file = fopen($fileName, 'a'); $csvFile = new Keboola\Csv\CsvWriter($file); $rows = [ [ 'col1', 'col2', ], [ 'first column', 'second column', ], ]; foreach ($rows as $row) { $csvFile->writeRow($row); } fclose($file);
Write CSV With Windows new-lines
$csvFile = new Keboola\Csv\CsvWriter( 'test-output.csv', CsvWriter::DEFAULT_DELIMITER, CsvWriter::DEFAULT_ENCLOSURE, "\r\n" ) $rows = [ [ 'col1', 'col2', ], [ 'first column', 'second column', ], ]; foreach ($rows as $row) { $csvFile->writeRow($row); }
Installation
The library is available as composer package. To start using this library in your project follow these steps:
Install package:
composer require keboola/csv
Add autoloader in your bootstrap script:
require 'vendor/autoload.php';
Read more in Composer documentation
Development
Clone this repository and init the workspace with following command:
git clone https://github.com/keboola/php-csv.git
cd php-csv
docker-compose build
docker-compose run --rm dev composer install --no-scripts
Run the test suite using this command:
docker-compose run --rm dev composer tests
License
MIT licensed, see LICENSE file.
keboola/csv 适用场景与选型建议
keboola/csv 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.82M 次下载、GitHub Stars 达 132, 最近一次更新时间为 2012 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「csv」 「rfc4180」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 keboola/csv 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 keboola/csv 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 keboola/csv 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Drop in replacement for native PHP CSV related functions to read and/or write RFC4180 compliant CSV files
Converting an array to CSV and vice versa.
laravel facade to read/write csv file
Collection of tools to use the full power of the Enyalius framework
Fast Excel import/export for Laravel
Spreadsheet reader library for Excel, OpenOffice and structured text files, compatible with cakephp3
统计信息
- 总下载量: 1.82M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 145
- 点击次数: 27
- 依赖项目数: 26
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-10-01