g105b/phpcsv
Composer 安装命令:
composer require g105b/phpcsv
包简介
Wraps SplFileObject's CSV capabilities with a more human approach
README 文档
README
Wraps SplFileObject's CSV capabilities with a more human approach
Features at a glance
- Enhances PHP's SplFileObject, a memory-efficient file stream.
- Simple filtering of rows by field value (
getAllBy("fieldName", "fieldValue")). - Results are associative arrays, the indices are the CSV header names.
- Iterate over CSV files by row.
- Reference CSV rows by row number.
- Reference CSV rows by ID value.
Screenshot in action
Usage
Here are a few use cases to best show the functionality of the library. For a complete guide, visit the documentation.
Add rows
$csv = new Csv("/path/to/file.csv"); $csv->add([ "firstName" => "Alan", "lastName" => "Statham", "Job Title" => "Consultant Radiologist", ]); $csv->add([ "firstName" => "Caroline", "lastName" => "Todd", "Job Title" => "Surgical Registrar", ]);
Get rows
$csv = new Csv("/path/to/file.csv"); $resultRows = $csv->getAllBy("gender", "F"); // array of all matching rows. $firstRow = $csv->getBy("gender", "F"); // single row, first matching.
Iterate over rows
$csv = new Csv("/path/to/file.csv"); foreach ($csv as $rowNumber => $row) { // $row is an associative array with CSV headers as each key. // $rowNumber starts from 1 (ignoring header row). }
Update row
$csv = new Csv("/path/to/file.csv"); $row = $csv->getBy("email", "barack@whitehouse.gov"); // Update the matching row with provided fields, keeping any // existing field data on the existing row. $csv->update($row, [ "dateOfBirth" => "1961-08-04", ]);
Delete row
$csv = new Csv("/path/to/file.csv"); // Delete a row by its index. $csv->deleteRow(22);
Future feature ideas
- Requesting only certain fields in result (v2)
- Type handling (v3)
- Sorting (v4)
- Faster retrieval of indexed rows (v4)
g105b/phpcsv 适用场景与选型建议
g105b/phpcsv 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.89k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「csv」 「import」 「filter」 「export」 「read」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 g105b/phpcsv 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 g105b/phpcsv 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 g105b/phpcsv 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Parse use statements for a reflection object
Tool for copying data from a production database to a dev database. Also useful for making backups of production databases.
A fork of konnco/filament-import with support of Laravel 11 since the default importer of Filament 3 is nonsense for basic use case.
统计信息
- 总下载量: 17.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-11
