daleattree/csvfilehandler
最新稳定版本:1.0.12
Composer 安装命令:
composer require daleattree/csvfilehandler
包简介
A library that loads and parses a CSV file, returning an object of the file with each CSV line as an object
README 文档
README
A library that loads and parses a CSV file, returning an object of the file with each CSV line as an object (License: GPL-2.0)
##Installation
###Included in a PHP Project w/ Composer
Add the following to your composer.json file using the latest version number or 1.0.* to keep it fresh:
"require": { "daleattree/csvfilehandler": "1.0.*" }
##Usage
$csvFileHandler = new daleattree\CsvFileHandler\CsvFileHandler($filename, [$headerRow = true], [$delimiter = ','], [$enclosure = '"'], [$escape = '\\'], [$autoParse = true]);
###Example
####CSV File Content
id,greeting1,greeting2,salutation
1,"Regards, Test",hello,"there"
Code
foreach($csvFileHandler->getRecords() as $record){ echo $record->getId() . PHP_EOL . $record->getGreeting2()() . ' ' . $record->getSalutation() . PHP_EOL . $record->getGreeting1() . PHP_EOL; }
If the CSV file is too large for it to be efficiently loaded into memory, you can set $autoParse to false and read one line at a time from the file.
while(false !== ($row = $this->handler->readRecord())){ //do something }
####Output
1
hello there
Regards, Test
If there is a header row, the column names will be camel-cased and accessible on RecordObject via get[ColumnName] and set[ColumnName] If there is no header row, column names default to col[n], n being the column index (zero-based).
统计信息
- 总下载量: 24.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2015-10-04