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

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

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

unicframework/csv-parser

Composer 安装命令:

composer require unicframework/csv-parser

包简介

CSVParser parse csv data to array, object, and json.

README 文档

README

Unic Logo

CSVParser library parse csv data to array, object, and json format. CSVParser convert array, object, json to csv format.

Features

  • Parse data from csv file, array, json and objects.
  • Parse csv to array and array to csv.
  • Parse csv to object and object to csv.
  • Parse csv to json and json to csv.
  • Set custom headers to csv file.

Installation

  • Install composer if you have not installed.
composer require unicframework/csv-parser

Parse Data

use CSVParser\CSV;

$csv = new CSV();

//Parse data from csv file
$csv->parse('data.csv');

//Parse array data
$csv->parse($arrayData);

//Parse object data
$csv->parse($jsonData);

//Parse json data
$csv->parse($objectData);

Get Parsed Data

//Get header
$header = $csv->getHeader();

//Get parsed data to array format
$data = $csv->toArray();

//Select data from parsed data
$data = $csv->toArray(['Name', 'Email']);

//Get parsed data to object format
$data = $csv->toObject();

//Select data from parsed data
$data = $csv->toObject(['Name', 'Email']);

//Get parsed data to json format
$data = $csv->toJson();

//Select data from parsed data
$data = $csv->toJson(['Name', 'Email']);

//Get parsed data to csv format
$data = $csv->toCsv();

//Select data from parsed data
$data = $csv->toCsv(['Name', 'Email']);

Get Row Count

//Get row count
$rows = $csv->rowCount();

//Get header count
$cols = $csv->headerCount();

Select Data Limit

//Select 10 records
$csv->limit(10);
$data = $csv->toArray();

//Select from 5 to 10 records
$csv->limit(5, 10);
$data = $csv->toArray();

Set CSV Header

//Ignore header from csv file
$csv->ignoreHeader(true);

//Ignore csv header cse
$csv->ignoreHeaderCase(true);

//Ignore csv enclosure
$csv->ignoreEnclosure(true);

//Set header offset of csv file
$csv->headerOffset(0);

//Set custom header to csv file
$csv->setHeader(['Name', 'Email']);

Set CSV Delimiter

Default csv delimiter is , but we can set other delimiter for csv file.

//Set delimiter
$csv->setDelimiter('|');

//Set enclosure
$csv->setEnclosure('"');

//Set escape character
$csv->setEscape('//');

//Parse csv file data
$csv->parse('data.csv');

//Get data from parsed data
$data = $csv->toArray();

Aggregate Functions

//Parse csv file data
$csv->parse('data.csv');

//Get total sum of given field
$total_price = $csv->sum('price');

//Get minimum from given field
$min_price = $csv->min('price');

//Get maximum from given field
$max_price = $csv->max('price');

//Get average of given field
$average_price = $csv->average('price');

License

MIT License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固