承接 originphp/csv 相关项目开发

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

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

originphp/csv

Composer 安装命令:

composer require originphp/csv

包简介

OriginPHP CSV

README 文档

README

license build coverage

The CSV utility makes it easy to work with CSV files.

Installation

To install this package

$ composer require originphp/csv

Create CSV from an Array

To use an array to create CSV data

use Origin\Csv\Csv;

$csv = Csv::fromArray([
    ['jim','jim@example.com'],
    ['tony','tony@example.com']
]);

Which will give you this

jim,jim@example.com
tony,tony@example.com

You can also use keys from the array as headers

use Origin\Csv\Csv;

$csv = Csv::fromArray([
        ['name'=>'jim','email'=>'jim@example.com'],
        ['name'=>'tony','email'=>'tony@example.com']
    ],['header'=>true]);

Which will return this

name,email
jim,jim@example.com
tony,tony@example.com

If you want to use custom headers

use Origin\Csv\Csv;

$csv = Csv::fromArray([
        ['name'=>'jim','email'=>'jim@example.com'],
        ['name'=>'tony','email'=>'tony@example.com']
    ],['header'=>['First Name','Email Address']]);

Which will gives you this

"First Name","Email Address"
jim,jim@example.com
tony,tony@example.com

Create an Array from CSV Data

Use the toArray method to create an array using CSV data.

use Origin\Csv\Csv;

$csv = file_get_contents('/path/file.csv');
$data = Csv::toArray($csv);

If the CSV file has a header row, then you can skip it by passing an options array with the key header set to true.

$data = Csv::toArray($csv,['header'=>true]);

If you want to use the headers as keys for each record in the array, this will use the first row as the keys for the array.

$data = Csv::toArray($csv,['header'=>true,'keys'=>true]);

If you want to set custom keys for each record in the array

$data = Csv::toArray($csv,['keys'=>['First Name','Email Address']]);

Processing Large Files

To process large CSV files in a memory efficient way use the process method, which takes the the same options as toArray. The difference here is that, it will reads the CSV file one line at a time, returns its for processing, then goes the next.

$rows = Csv::process('/path/to/file.csv',['keys'=>['First Name','Email Address']]);
foreach($rows as $row){
    ... do something
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固