ork/csv
最新稳定版本:2.3.0
Composer 安装命令:
composer require ork/csv
包简介
A library to read and write CSV files.
README 文档
README
Ork CSV is a library for reading and writing CSV files.
Installation
composer require ork/csv
Reader
Ork CSV provides a reader to parse delimited files into arrays. The reader is implemented as an iterator that yields the contents of one CSV line per iteration. If the file has a header line with column names, each yielded array will be associative, keyed by the names in the header. If the file does not have a header line with columns names, each yielded array will be indexed.
For example, a file with a header line:
ID,Name,Size
1,foo,large
2,bar,small
$csv = new \Ork\Csv\Reader('/path/to/file.csv'); foreach ($csv as $row) { print_r($row); }
Array
(
[ID] => 1
[Name] => foo
[Size] => large
)
Array
(
[ID] => 2
[Name] => bar
[Size] => small
)
A file without a header line:
1,foo,large
2,bar,small
$csv = new \Ork\Csv\Reader(file: '/path/to/file.csv', hasHeader: false); foreach ($csv as $row) { print_r($row); }
Array
(
[0] => 1
[1] => foo
[2] => large
)
Array
(
[0] => 2
[1] => bar
[2] => small
)
Writer
Ork CSV provides a writer that will track columns and automatically generate an appropriate header line.
$csv = new \Ork\Csv\Writer('/path/to/file.csv'); $csv->write([ 'Id' => 1, 'Name' => 'foo', 'Size' => 'large', ]); $csv->write([ 'Id' => 2, 'Name' => 'bar', 'Size' => 'small', ]);
Id,Name,Size
1,foo,large
2,bar,small
See the docs directory for full details.
统计信息
- 总下载量: 129
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-27