承接 g105b/phpcsv 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

g105b/phpcsv

最新稳定版本:v1.0.3

Composer 安装命令:

composer require g105b/phpcsv

包简介

Wraps SplFileObject's CSV capabilities with a more human approach

README 文档

README

Wraps SplFileObject's CSV capabilities with a more human approach

Build status Composer Version Download Stats

Features at a glance

  • Enhances PHP's SplFileObject, a memory-efficient file stream.
  • Simple filtering of rows by field value (getAllBy("fieldName", "fieldValue")).
  • Results are associative arrays, the indices are the CSV header names.
  • Iterate over CSV files by row.
  • Reference CSV rows by row number.
  • Reference CSV rows by ID value.

Screenshot in action

Screenshot of phpcsv

Usage

Here are a few use cases to best show the functionality of the library. For a complete guide, visit the documentation.

Add rows

$csv = new Csv("/path/to/file.csv");
$csv->add([
    "firstName" => "Alan",
    "lastName" => "Statham",
    "Job Title" => "Consultant Radiologist",
]);
$csv->add([
    "firstName" => "Caroline",
    "lastName" => "Todd",
    "Job Title" => "Surgical Registrar",
]);

Get rows

$csv = new Csv("/path/to/file.csv");
$resultRows = $csv->getAllBy("gender", "F"); // array of all matching rows.
$firstRow = $csv->getBy("gender", "F"); // single row, first matching.

Iterate over rows

$csv = new Csv("/path/to/file.csv");

foreach ($csv as $rowNumber => $row) {
    // $row is an associative array with CSV headers as each key.
    // $rowNumber starts from 1 (ignoring header row).
}

Update row

$csv = new Csv("/path/to/file.csv");
$row = $csv->getBy("email", "barack@whitehouse.gov");

// Update the matching row with provided fields, keeping any
// existing field data on the existing row.
$csv->update($row, [
    "dateOfBirth" => "1961-08-04",
]);

Delete row

$csv = new Csv("/path/to/file.csv");

// Delete a row by its index.
$csv->deleteRow(22);

Future feature ideas

  • Requesting only certain fields in result (v2)
  • Type handling (v3)
  • Sorting (v4)
  • Faster retrieval of indexed rows (v4)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固