Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jwage/easy-csv
EasyCSV is a simple Object Oriented CSV manipulation library for PHP 7.2+
https://github.com/jwage/easy-csv
csv csv-reader php
Last synced: about 4 hours ago
JSON representation
EasyCSV is a simple Object Oriented CSV manipulation library for PHP 7.2+
- Host: GitHub
- URL: https://github.com/jwage/easy-csv
- Owner: jwage
- License: mit
- Created: 2009-11-13T23:24:05.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2021-04-08T22:20:41.000Z (almost 4 years ago)
- Last Synced: 2024-05-17T07:02:26.152Z (8 months ago)
- Topics: csv, csv-reader, php
- Language: PHP
- Homepage:
- Size: 84 KB
- Stars: 253
- Watchers: 12
- Forks: 58
- Open Issues: 7
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE
Awesome Lists containing this project
README
EasyCSV
=======EasyCSV is a simple Object Oriented CSV manipulation library for PHP 7.2+
[![Build Status](https://secure.travis-ci.org/jwage/easy-csv.png?branch=master)](http://travis-ci.org/jwage/easy-csv)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/jwage/easy-csv/badges/quality-score.png?s=7e0e1d4b5d7f6be61a3cd804dba556a0e4d1141d)](https://scrutinizer-ci.com/g/jwage/easy-csv/)
[![Code Coverage](https://scrutinizer-ci.com/g/jwage/easy-csv/badges/coverage.png?s=a02332bc4d6a32df3171f2ba714e4583a70c0154)](https://scrutinizer-ci.com/g/jwage/easy-csv/)
[![Latest Stable Version](https://poser.pugx.org/jwage/easy-csv/v/stable.png)](https://packagist.org/packages/jwage/easy-csv)
[![Total Downloads](https://poser.pugx.org/jwage/easy-csv/downloads.png)](https://packagist.org/packages/jwage/easy-csv)## Installation
Install via [composer](https://getcomposer.org/):
```sh
composer require jwage/easy-csv
```## Reader
To read CSV files we need to instantiate the EasyCSV reader class:
```php
$reader = new \EasyCSV\Reader('read.csv');
```You can iterate over the rows one at a time:
```php
while ($row = $reader->getRow()) {
print_r($row);
}
```Or you can get everything all at once:
```php
print_r($reader->getAll());
```If you have a file with the header in a different line:
```php
// our headers aren't on the first line
$reader = new \EasyCSV\Reader('read.csv', 'r+', false);
// zero-based index, so this is line 4
$reader->setHeaderLine(3);
```Advance to a different line:
```
$reader->advanceTo(6);
```More in the Reader unit test.
## Writer
To write CSV files we need to instantiate the EasyCSV writer class:
```php
$writer = new \EasyCSV\Writer('write.csv');
```You can write a row by passing a commas separated string:
```php
$writer->writeRow('column1, column2, column3');
```Or you can pass an array:
```php
$writer->writeRow(array('column1', 'column2', 'column3'));
```You can also write several rows at once:
```php
$writer->writeFromArray(array(
'value1, value2, value3',
array('value1', 'value2', 'value3')
));
```