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

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

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

paalg/csv

最新稳定版本:v0.1.0

Composer 安装命令:

composer require paalg/csv

包简介

A little library handling CSV files

README 文档

README

This library is for parsing an iterating through lines in a CSV file.

Versions

  • v0.1 The first version published

Usage

// Load standard CSV file with headers and "," as field separator
$csv = new Csv('import.csv');
$data = $csv->getData();
print_r($data);
print_r($csv->getHeaders());

The output of above code can be like this:

Array
(
    [0] => Array
        (
            [Year] => 1997
            [Make] => Ford
            [Model] => E350
            [Description] => ac, abs, moon
            [Price] => 3000.00
        )

    [1] => Array
        (
            [Year] => 1999
            [Make] => Chevy
            [Model] => Venture "Extended Edition"
            [Description] => 
            [Price] => 4900.00
        )
)
Array
(
    [0] => Year
    [1] => Make
    [2] => Model
    [3] => Description
    [4] => Price
)

If you need to iterate the CSV file, you can do this:

$csv = new Csv('data.csv');
foreach ($csv as $row) {    
    print_r($row);
    foreach ($row as $fieldName => $value) {
        // do things with the fields in current row
    }
}

One iteration of above script will output something like this:

Array
(
    [Year] => 1999
    [Make] => Chevy
    [Model] => Venture "Extended Edition"
    [Description] =>
    [Price] => 4900.00
)

Unit testing

The library has been thoroughly tested with unit tests (phpunit). You can run the tests with command composer test.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: apache-2.0
  • 更新时间: 2023-09-11