定制 yogarine/csv-utils 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yogarine/csv-utils

最新稳定版本:v1.0.1

Composer 安装命令:

composer require yogarine/csv-utils

包简介

CSV utils by Yogarine

关键字:

README 文档

README

This library currently contains the CsvFile class, which makes it easy to iterate through CSV files of any size and makeup.

Installation

composer require "yogarine/csv-utils:^1.0"

CsvFile

The CsvFile class makes it easy to iterate through CSV files of any size. It implements Iterator and SeekableIterator so you can easily loop through the CSV using foreach:

Usage

Let's say you have a file called foo.csv with the following content:

id,name,description
0,foo,"This is a Foo"
1,bar,"This is a Bar"
2,baz,"This is a Baz"
3,qux,"This is a Qux"

You can iterate through it like this:

$csvFile = new CsvFile('foo.csv');

foreach ($csvFile as $row) {
	$id          = $row['id'];
	$name        = $row['name'];
	$description = $row['description'];
}

No header row

If your CSV doesn't have a header row:

0,foo,"This is a Foo"
1,bar,"This is a Bar"
2,baz,"This is a Baz"
3,qux,"This is a Qux"

Use the $headerRow argument to omit it:

$csvFile = new CsvFile('foo.csv', CsvFile::HEADER_ROW_NONE);

foreach ($csvFile as $row) {
	list($id, $name, $description) = $row;
}

Other formats

Other formats, like PSV or TSV are also supported:

id|name|description
0|foo|"This is a Foo"
1|bar|"This is a Bar"
2|baz|"This is a Baz"
3|qux|"This is a Qux"
$csvFile = new CsvFile('foo.csv', 0, '|');

统计信息

  • 总下载量: 93.6k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2019-02-04