2017 © Pedro Peláez
 

library csv

Keboola CSV reader and writer

image

keboola/csv

Keboola CSV reader and writer

  • Tuesday, July 17, 2018
  • by Halama
  • Repository
  • 10 Watchers
  • 99 Stars
  • 481,345 Installations
  • PHP
  • 22 Dependents
  • 0 Suggesters
  • 30 Forks
  • 5 Open issues
  • 30 Versions
  • 3 % Grown

The README.md

Keboola CSV reader/writer

Latest Stable Version License Total Downloads, (*1)

The library provides a simple reader and writer for CSV files according to RFC4180. The library is licensed under the MIT license. The library provides classes CsvReader and CsvWriter for reading and writing CSV files. The classes are designed to be immutable and minimalistic., (*2)

Usage

Read CSV

$csvFile = new Keboola\Csv\CsvReader(__DIR__ . '/_data/test-input.csv');
foreach($csvFile as $row) {
    var_dump($row);
}

Skip lines

Skip the first line:, (*3)

$csvFile = new \Keboola\Csv\CsvFile(
    $fileName,
    CsvFile::DEFAULT_DELIMITER,
    CsvFile::DEFAULT_ENCLOSURE,
    CsvFile::DEFAULT_ESCAPED_BY,
    1
)
foreach($csvFile as $row) {
    var_dump($row);
}

Write CSV

$csvFile = new Keboola\Csv\CsvWriter(__DIR__ . '/_data/test-output.csv');
$rows = [
    [
        'col1', 'col2',
    ],
    [
        'first column', 'second column',
    ],
];

foreach ($rows as $row) {
    $csvFile->writeRow($row);
}

Append to CSV

$fileName = __DIR__ . '/_data/test-output.csv';
$file = fopen($fileName, 'a');
$csvFile = new Keboola\Csv\CsvWriter($file);
$rows = [
    [
        'col1', 'col2',
    ],
    [
        'first column', 'second column',
    ],
];

foreach ($rows as $row) {
    $csvFile->writeRow($row);
}
fclose($file);

Write CSV With Windows new-lines

$csvFile = new Keboola\Csv\CsvWriter(
    'test-output.csv',
    CsvWriter::DEFAULT_DELIMITER,
    CsvWriter::DEFAULT_ENCLOSURE,
    "\r\n"
)
$rows = [
    [
        'col1', 'col2',
    ],
    [
        'first column', 'second column',
    ],
];

foreach ($rows as $row) {
    $csvFile->writeRow($row);
}

Installation

The library is available as composer package. To start using this library in your project follow these steps:, (*4)

Install package:, (*5)

composer require keboola/csv

Add autoloader in your bootstrap script:, (*6)

require 'vendor/autoload.php';

Read more in Composer documentation, (*7)

Development

Clone this repository and init the workspace with following command:, (*8)

git clone https://github.com/keboola/php-csv.git
cd php-csv
docker-compose build
docker-compose run --rm dev composer install --no-scripts

Run the test suite using this command:, (*9)

docker-compose run --rm dev composer tests

License

MIT licensed, see LICENSE file., (*10)

The Versions

17/07 2018

dev-najlos-tsv

dev-najlos-tsv http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

18/05 2018

dev-master

9999999-dev http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

18/05 2018

2.0.0

2.0.0.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

18/05 2018

dev-martin-mac-osx-lines

dev-martin-mac-osx-lines http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

18/05 2018

dev-ssmusoke-master

dev-ssmusoke-master http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

14/05 2018

dev-odin-reader-writer

dev-odin-reader-writer http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

14/05 2018

1.4.2

1.4.2.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

12/05 2018

1.4.1

1.4.1.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

13/04 2018

1.4.0

1.4.0.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

12/04 2018

dev-odin-string-obj

dev-odin-string-obj http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

11/04 2018

1.3.0

1.3.0.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

11/04 2018

1.3.1

1.3.1.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

17/02 2018

dev-renovation

dev-renovation http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Avatar Keboola

csv rfc4180

16/02 2018

1.2.0

1.2.0.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Development Requires

16/02 2018

dev-skip-lines-2

dev-skip-lines-2 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Development Requires

21/04 2016

1.1.4

1.1.4.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Development Requires

31/01 2014

1.1.3

1.1.3.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Development Requires

10/10 2013

1.1.2

1.1.2.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Development Requires

24/09 2013

1.1.1

1.1.1.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

MIT

The Development Requires

23/04 2013

1.1.0

1.1.0.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

The Development Requires

21/11 2012

1.0.9

1.0.9.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

16/10 2012

1.0.8

1.0.8.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

11/10 2012

1.0.7

1.0.7.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

11/10 2012

1.0.6

1.0.6.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

04/10 2012

1.0.5

1.0.5.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

02/10 2012

1.0.3

1.0.3.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

02/10 2012

1.0.4

1.0.4.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

02/10 2012

1.0.2

1.0.2.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

01/10 2012

1.0.1

1.0.1.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download

01/10 2012

1.0.0

1.0.0.0 http://keboola.com

Keboola CSV reader and writer

  Sources   Download