atk14/csv-reader
Composer 安装命令:
composer require atk14/csv-reader
包简介
Reads CSV data from a file or a string, detects automatically CSV format parameters
关键字:
README 文档
README
Reads CSV data from a file or a string. Detects automatically CSV format parameters.
Basic usage
$csv_data = '
k1;k2;k3
v1;v2;v3
x1;x2;x3
y1;y2
z1
';
$csv_data = trim($csv_data);
$reader = CsvReader::FromData($csv_data);
// or
$reader = CsvReader::FromFile("path/to/file.csv");
$reader->getRowCount(); // 5
$reader->getColumnCount(); // 3
$rows = $reader->getRows();
// [
// ["k1","k2","k3"],
// ["v1","v2","v3"],
// ["x1","x2","x3"],
// ["y1","y2",""],
// ["z1","",""],
// ]
$rows = $reader->getRows(["offset" => 2]);
// [
// ["x1","x2","x3"],
// ["y1","y2",""],
// ["z1","",""],
// ]
$row = $reader->getRow(0);
// ["k1","k2","k3"]
$row = $reader->getRow(1);
// ["v1","v2","v3"]
$col = $reader->getColumn(0);
// ["k1","v1","x1","y1","z1"],
$col = $reader->getColumn(0,["offset" => 1]);
// ["v1","x1","y1","z1"],
$col = $reader->getColumn(2);
// ["k3","v3","x3","",""],
$col = $reader->getColumn(3);
// []
$rows = $reader->getAssociativeRows();
// [
// ["k1" => "v1", "k1" => "v2", "k3" => "v3"],
// ["k1" => "x1", "k1" => "x2", "k3" => "x3"],
// ["k1" => "y1", "k1" => "y2", "k3" => ""],
// ["k1" => "z1", "k1" => "", "k3" => ""],
// ]
$rows = $reader->getAssociativeRows(["header_line" => 1]); // counting from 0, so this is the 2nd line
// [
// ["v1" => "x1", "v1" => "x2", "v3" => "x3"],
// ["v1" => "y1", "v1" => "y2", "v3" => ""],
// ["v1" => "z1", "v1" => "", "v3" => ""],
// ]
$rows = $reader->getAssociativeRows(["keys" => ["f1","f2","f3"]]);
// [
// ["f1" => "k1", "k1" => "k2", "k3" => "k3"],
// ["f1" => "v1", "k1" => "v2", "k3" => "v3"],
// ["f1" => "x1", "k1" => "x2", "k3" => "x3"],
// ["f1" => "y1", "k1" => "y2", "k3" => ""],
// ["f1" => "z1", "k1" => "", "k3" => ""],
// ]
$rows = $reader->getAssociativeRows(["keys" => ["f1","f2","f3"], "offset" => 2]);
// [
// ["f1" => "x1", "k1" => "x2", "k3" => "x3"],
// ["f1" => "y1", "k1" => "y2", "k3" => ""],
// ["f1" => "z1", "k1" => "", "k3" => ""],
// ]
CSV format parameters auto-detection
The CsvReader detects format parameters automatically. If the auto-detection fails, format parameters can be specified explicitly.
$reader = CsvReader::FromData($csv_data,[
"delimiter" => ";",
"quote" => "'"
]);
// or
$reader = CsvReader::FromFile("path/to/file.csv",[
"delimiter" => ";",
"quote" => "'"
]);
Installation
composer require atk14/cvs-reader
Testing
composer update --dev
./vendor/bin/run_unit_tests test
License
CsvReader is free software distributed under the terms of the MIT license
atk14/csv-reader 适用场景与选型建议
atk14/csv-reader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30.4k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 07 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「csv」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 atk14/csv-reader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atk14/csv-reader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 atk14/csv-reader 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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
A formatting library that converts data output between XML, CSV, JSON, TXT, YAML and a few others.
Scan URLs FROM A CSV FILE AND REPORT INACCESSIBLE URLs
统计信息
- 总下载量: 30.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-13