taranto/csv-parser 问题修复 & 功能扩展

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

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

taranto/csv-parser

Composer 安装命令:

composer require taranto/csv-parser

包简介

CSV parser for PHP7.0 or later

README 文档

README

Build Status Coverage Status License: MIT

CSV Parser

An easy to use CSV parser

Features

  • Converts CSV to arrays and arrays indexed by the first row cells (headers);
  • Automatically guesses CSV fields delimiter;
  • Provides limit and offset options for parsing;
  • Performance wise parsing while using as an iterator.

Requirements

  • PHP 7.0 or later.

Installation

composer require taranto/csv-parser

Usage

Parsing a CSV file to an array:

$csvParser = new CsvParser('file.csv');
$csvAsArray = $csvParser->getCsvAsArray();

Parsing a CSV file to an array indexed by the first row cells (headers):

$csvParser = new CsvParser('file.csv');
$csvAsArray = $csvParser->getCsvAsAssociativeArray();

Performance wise usage (good for large files):

  • Simple arrays
$csvParser = new CsvParser('file.csv');
$csvAsArray = [];
foreach ($csvParser as $row) {
    $csvAsArray[] = $row;
}
  • Associative arrays
$csvParser = new CsvParser('file.csv', true);
$csvAsArray = [];
foreach ($csvParser as $row) {
    $csvAsArray[] = $row;
}

Example

Given the CSV

| name  | birthdate   | 
| John  |  1985-02-03 | 
|  Kim  |  1976-05-04 | 
|  Suzy |  1991-04-02 |
|  Tom  |  1970-01-03 |

Parsing to an associtive array with offset(1) and limit(2):

$csvParser = new CsvParser('file.csv');
$csvAsArray = $csvParser->getCsvAsAssociativeArray(1, 2);

Returns:

[
    ["name" => "Kim", "birthdate" => "1976-05-04"]
    ["name" => "Suzy", "birthdate" => "1991-04-02"]
]

Author

License

This project is licensed under the MIT License - see the LICENSE.txt file for details

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固