2017 © Pedro PelĂĄez
 

library csv

A library for easily reading and writing CSV files

image

mmerian/csv

A library for easily reading and writing CSV files

  • Tuesday, March 15, 2016
  • by mmerian
  • Repository
  • 2 Watchers
  • 5 Stars
  • 1,056 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 2 Open issues
  • 9 Versions
  • 32 % Grown

The README.md

csv

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

This library is designed to help you read and write csv files., (*2)

Usage

Reading CSV files

Say you have a CSV file that looks like this :, (*3)

first_name;last_name;gender;birthdate
John;Smith;M;1972-05-12
Susan;Chatman;F;1972-05-12

Instanciating the reader is really easy :, (*4)


use Csv\Reader; $reader = new Reader($file, array( 'hasHeader' => true, 'inputEncoding' => 'ISO-8859-15', 'outputEncoding' => 'UTF-8', 'delimiter' => ';' )); foreach ($reader as $line) { /* * $line is an array. * If the CSV file has an header, * the array keys are the header fields */ echo $line['first_name']; } // Or while ($line = $reader->fetch()) { // Process line }

In this example, $file can be the path to an existing file, or a pointer to an already open file. Available options are :, (*5)

  • 'hasHeader' : A boolean determining if the first line of the CSV file is a head with fields names
  • 'header' : If the CSV file doesn't have a header, you can provide one here. If both 'header' and 'hasHeader' are provided, the 'header' option takes precedence
  • 'inputEncoding' : The encoding of the CSV file. Defaults to UTF-8
  • 'outputEncoding' : The encoding of the data that will be returned when reading the file. If 'inputEncoding' and 'outputEncoding' are different, the reader automatically uses mbstring to convert
  • 'delimiter' : The CSV delimiter
  • 'enclosure' : The CSV enclosure
  • 'ignoreEmptyLines': If set to true (the default), the reader will silently ignore empty lines. Otherwise, an exception will be raised if an empty line is encountered

Automatic field processing

The reader is also able to apply formatting functions to your CSV fields., (*6)


use Csv\Reader; $reader = new Reader($file, array( 'hasHeader' => true, 'inputEncoding' => 'ISO-8859-15', 'outputEncoding' => 'UTF-8', 'delimiter' => ';' )); $reader->registerFormatter('birthdate', function($date) { return preg_replace('/^([0-9]+)-([0-9]+)-([0-9]+)$/', '$3/$2/$1', $date); }); foreach ($reader as $line) { echo $line['birthdate']; // will echo 12/05/1972 for the first line }

The Versions

15/03 2016

dev-master

9999999-dev

A library for easily reading and writing CSV files

  Sources   Download

MIT

The Requires

  • php >= 5.3.0
  • ext-mbstring *

 

by Maxime Mérian

csv data processing

15/03 2016

1.0.10

1.0.10.0

A library for easily reading and writing CSV files

  Sources   Download

MIT

The Requires

  • php >= 5.3.0
  • ext-mbstring *

 

by Maxime Mérian

csv data processing

15/03 2016

1.0.9

1.0.9.0

A library for easily reading and writing CSV files

  Sources   Download

MIT

The Requires

  • php >= 5.3.0
  • ext-mbstring *

 

by Maxime Mérian

csv data processing

13/11 2015

1.0.8

1.0.8.0

A library for easily reading and writing CSV files

  Sources   Download

MIT

The Requires

  • php >= 5.3.0
  • ext-mbstring *

 

by Maxime Mérian

csv data processing

28/05 2015

1.0.7

1.0.7.0

A library for easily reading and writing CSV files

  Sources   Download

MIT

The Requires

  • php >= 5.3.0
  • ext-mbstring *

 

by Maxime Mérian

csv data processing

17/10 2014

1.0.6

1.0.6.0

A library for easily reading and writing CSV files

  Sources   Download

MIT

by Maxime Mérian

csv data processing

01/02 2014

1.0.5

1.0.5.0

A library for easily reading and writing CSV files

  Sources   Download

MIT

by Maxime Mérian

csv data processing

19/09 2013

1.0.1

1.0.1.0

A library for easily reading and writing CSV files

  Sources   Download

by Maxime Mérian

csv data processing

10/09 2013

1.0.0

1.0.0.0

A CSV data processing library

  Sources   Download

by Maxime Mérian

csv data processing