mmerian/csv
Composer 安装命令:
composer require mmerian/csv
包简介
A library for easily reading and writing CSV files
关键字:
README 文档
README
This library is designed to help you read and write csv files.
Usage
Reading CSV files
Say you have a CSV file that looks like this :
first_name;last_name;gender;birthdate
John;Smith;M;1972-05-12
Susan;Chatman;F;1972-05-12
Instanciating the reader is really easy :
use Csv\Reader; $reader = new Reader($file, array( 'hasHeader' => true, 'inputEncoding' => 'ISO-8859-15', 'outputEncoding' => 'UTF-8', 'delimiter' => ';' )); foreach ($reader as $line) { /* * $line is an array. * If the CSV file has an header, * the array keys are the header fields */ echo $line['first_name']; } // Or while ($line = $reader->fetch()) { // Process line }
In this example, $file can be the path to an existing file, or a pointer to an already open file.
Available options are :
'hasHeader': A boolean determining if the first line of the CSV file is a head with fields names'header': If the CSV file doesn't have a header, you can provide one here. If both'header'and'hasHeader'are provided, the'header'option takes precedence'inputEncoding': The encoding of the CSV file. Defaults to UTF-8'outputEncoding': The encoding of the data that will be returned when reading the file. If'inputEncoding'and'outputEncoding'are different, the reader automatically uses mbstring to convert'delimiter': The CSV delimiter'enclosure': The CSV enclosure'ignoreEmptyLines': If set to true (the default), the reader will silently ignore empty lines. Otherwise, an exception will be raised if an empty line is encountered
Automatic field processing
The reader is also able to apply formatting functions to your CSV fields.
use Csv\Reader; $reader = new Reader($file, array( 'hasHeader' => true, 'inputEncoding' => 'ISO-8859-15', 'outputEncoding' => 'UTF-8', 'delimiter' => ';' )); $reader->registerFormatter('birthdate', function($date) { return preg_replace('/^([0-9]+)-([0-9]+)-([0-9]+)$/', '$3/$2/$1', $date); }); foreach ($reader as $line) { echo $line['birthdate']; // will echo 12/05/1972 for the first line }
mmerian/csv 适用场景与选型建议
mmerian/csv 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.65k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2013 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「data」 「csv」 「processing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mmerian/csv 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mmerian/csv 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mmerian/csv 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
paywant api php client
Convert and operate with FIPS codes for states, counties, etc.
Data provider for yii2
统计信息
- 总下载量: 9.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-09-18