keboola/csv 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

keboola/csv

最新稳定版本:4.1.0

Composer 安装命令:

composer require keboola/csv

包简介

Keboola CSV reader and writer

关键字:

README 文档

README

Latest Stable Version License Total Downloads

The library provides a simple reader and writer for CSV files according to RFC4180. The library is licensed under the MIT license. The library provides classes CsvReader and CsvWriter for reading and writing CSV files. The classes are designed to be immutable and minimalistic.

Usage

Read CSV

$csvFile = new Keboola\Csv\CsvReader(__DIR__ . '/_data/test-input.csv');
foreach($csvFile as $row) {
	var_dump($row);
}

Skip lines

Skip the first line:

$csvFile = new \Keboola\Csv\CsvFile(
    $fileName,
    CsvFile::DEFAULT_DELIMITER,
    CsvFile::DEFAULT_ENCLOSURE,
    CsvFile::DEFAULT_ESCAPED_BY,
    1
)
foreach($csvFile as $row) {
	var_dump($row);
}

Write CSV

$csvFile = new Keboola\Csv\CsvWriter(__DIR__ . '/_data/test-output.csv');
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}

Append to CSV

$fileName = __DIR__ . '/_data/test-output.csv';
$file = fopen($fileName, 'a');
$csvFile = new Keboola\Csv\CsvWriter($file);
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}
fclose($file);

Write CSV With Windows new-lines

$csvFile = new Keboola\Csv\CsvWriter(
    'test-output.csv',
    CsvWriter::DEFAULT_DELIMITER,
    CsvWriter::DEFAULT_ENCLOSURE,
    "\r\n"
)
$rows = [
	[
		'col1', 'col2',
	],
	[
		'first column', 'second column',
	],
];

foreach ($rows as $row) {
	$csvFile->writeRow($row);
}

Installation

The library is available as composer package. To start using this library in your project follow these steps:

Install package:

composer require keboola/csv

Add autoloader in your bootstrap script:

require 'vendor/autoload.php';

Read more in Composer documentation

Development

Clone this repository and init the workspace with following command:

git clone https://github.com/keboola/php-csv.git
cd php-csv
docker-compose build
docker-compose run --rm dev composer install --no-scripts

Run the test suite using this command:

docker-compose run --rm dev composer tests

License

MIT licensed, see LICENSE file.

统计信息

  • 总下载量: 1.71M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 146
  • 点击次数: 1
  • 依赖项目数: 26
  • 推荐数: 0

GitHub 信息

  • Stars: 133
  • Watchers: 21
  • Forks: 36
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-10-01