PHPackages                             handcraftedinthealps/goodby-csv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. handcraftedinthealps/goodby-csv

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

handcraftedinthealps/goodby-csv
===============================

CSV import/export library

1.4.3(11mo ago)441.6M—6.1%5[1 PRs](https://github.com/handcraftedinthealps/goodby-csv/pulls)3MITPHPPHP &gt;=7.2

Since Nov 26Pushed 11mo agoCompare

[ Source](https://github.com/handcraftedinthealps/goodby-csv)[ Packagist](https://packagist.org/packages/handcraftedinthealps/goodby-csv)[ Docs](https://github.com/handcraftedinthealps/goodby-csv)[ RSS](/packages/handcraftedinthealps-goodby-csv/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (7)Versions (5)Used By (3)Security (1)

Goodby, CSV
===========

[](#goodby-csv)

> This is a fork of [goodby-csv](https://github.com/goodby/csv/) to add support for PHP 8.1.

What is "Goodby CSV"?
---------------------

[](#what-is-goodby-csv)

Goodby CSV is a highly memory efficient, flexible and extendable open-source CSV import/export library.

```
use Goodby\CSV\Import\Standard\Lexer;
use Goodby\CSV\Import\Standard\Interpreter;
use Goodby\CSV\Import\Standard\LexerConfig;

$lexer = new Lexer(new LexerConfig());
$interpreter = new Interpreter();
$interpreter->addObserver(function(array $row) {
    // do something here.
	// for example, insert $row to database.
});
$lexer->parse('data.csv', $interpreter);
```

### Features

[](#features)

#### 1. Memory Management Free

[](#1-memory-management-free)

This library was designed for low memory usage. It will not accumulate all the rows in the memory. The importer reads a CSV file and executes a callback function line by line.

#### 2. Multibyte support

[](#2-multibyte-support)

This library supports mulitbyte input/output: for example, SJIS-win, EUC-JP and UTF-8.

#### 3. Ready to Use for Enterprise Applications

[](#3-ready-to-use-for-enterprise-applications)

Goodby CSV is fully unit-tested. The library is stable and ready to be used in large projects like enterprise applications.

Requirements
------------

[](#requirements)

- PHP 7.2 or later

Installation
------------

[](#installation)

Install the package via [composer](https://getcomposer.org/):

```
composer require handcraftedinthealps/goodby-csv
```

Documentation
-------------

[](#documentation)

### Configuration

[](#configuration)

Import configuration:

```
use Goodby\CSV\Import\Standard\LexerConfig;

$config = new LexerConfig();
$config
    ->setDelimiter("\t") // Customize delimiter. Default value is comma(,)
    ->setEnclosure("'")  // Customize enclosure. Default value is double quotation(")
    ->setEscape("\\")    // Customize escape character. Default value is backslash(\)
    ->setToCharset('UTF-8') // Customize target encoding. Default value is null, no converting.
    ->setFromCharset('SJIS-win') // Customize CSV file encoding. Default value is null.
;
```

Export configuration:

```
use Goodby\CSV\Export\Standard\ExporterConfig;

$config = new ExporterConfig();
$config
    ->setDelimiter("\t") // Customize delimiter. Default value is comma(,)
    ->setEnclosure("'")  // Customize enclosure. Default value is double quotation(")
    ->setEscape("\\")    // Customize escape character. Default value is backslash(\)
    ->setToCharset('SJIS-win') // Customize file encoding. Default value is null, no converting.
    ->setFromCharset('UTF-8') // Customize source encoding. Default value is null.
    ->setFileMode(CsvFileObject::FILE_MODE_WRITE) // Customize file mode and choose either write or append. Default value is write ('w'). See fopen() php docs
;
```

### Unstrict Row Consistency Mode

[](#unstrict-row-consistency-mode)

By default, Goodby CSV throws `StrictViolationException` when it finds a row with a different column count to other columns. In the case you want to import such a CSV, you can call `Interpreter::unstrict()` to disable row consistency check at import.

rough.csv:

```
foo,bar,baz
foo,bar
foo
foo,bar,baz
```

```
use Goodby\CSV\Import\Standard\Interpreter;
use Goodby\CSV\Import\Standard\Lexer;
use Goodby\CSV\Import\Standard\LexerConfig;

$interpreter = new Interpreter();
$interpreter->unstrict(); // Ignore row column count consistency

$lexer = new Lexer(new LexerConfig());
$lexer->parse('rough.csv', $interpreter);
```

Examples
--------

[](#examples)

### Import to Database via PDO

[](#import-to-database-via-pdo)

user.csv:

```
1,alice,alice@example.com
2,bob,bob@example.com
3,carol,carol@eample.com
```

```
use Goodby\CSV\Import\Standard\Lexer;
use Goodby\CSV\Import\Standard\Interpreter;
use Goodby\CSV\Import\Standard\LexerConfig;

$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'root');
$pdo->query('CREATE TABLE IF NOT EXISTS user (id INT, `name` VARCHAR(255), email VARCHAR(255))');

$config = new LexerConfig();
$lexer = new Lexer($config);

$interpreter = new Interpreter();

$interpreter->addObserver(function(array $columns) use ($pdo) {
    $stmt = $pdo->prepare('INSERT INTO user (id, name, email) VALUES (?, ?, ?)');
    $stmt->execute($columns);
});

$lexer->parse('user.csv', $interpreter);
```

### Import from TSV (tab separated values) to array

[](#import-from-tsv-tab-separated-values-to-array)

temperature.tsv:

```
9	Tokyo
27	Singapore
-5	Seoul
7	Shanghai
```

```
use Goodby\CSV\Import\Standard\Lexer;
use Goodby\CSV\Import\Standard\Interpreter;
use Goodby\CSV\Import\Standard\LexerConfig;

$temperature = [];

$config = new LexerConfig();
$config->setDelimiter("\t");
$lexer = new Lexer($config);

$interpreter = new Interpreter();
$interpreter->addObserver(function(array $row) use (&$temperature) {
    $temperature[] = [
        'temperature' => $row[0],
        'city'        => $row[1],
    ];
});

$lexer->parse('temperature.tsv', $interpreter);

print_r($temperature);
```

### Export from array

[](#export-from-array)

```
use Goodby\CSV\Export\Standard\Exporter;
use Goodby\CSV\Export\Standard\ExporterConfig;

$config = new ExporterConfig();
$exporter = new Exporter($config);

$exporter->export('php://output', [
    ['1', 'alice', 'alice@example.com'],
    ['2', 'bob', 'bob@example.com'],
    ['3', 'carol', 'carol@example.com'],
]);
```

### Export from database via PDO

[](#export-from-database-via-pdo)

```
use Goodby\CSV\Export\Standard\Exporter;
use Goodby\CSV\Export\Standard\ExporterConfig;
use Goodby\CSV\Export\Standard\CsvFileObject;
use Goodby\CSV\Export\Standard\Collection\PdoCollection;

$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'root');

$pdo->query('CREATE TABLE IF NOT EXISTS user (id INT, `name` VARCHAR(255), email VARCHAR(255))');
$pdo->query("INSERT INTO user VALUES(1, 'alice', 'alice@example.com')");
$pdo->query("INSERT INTO user VALUES(2, 'bob', 'bob@example.com')");
$pdo->query("INSERT INTO user VALUES(3, 'carol', 'carol@example.com')");

$config = new ExporterConfig();
$exporter = new Exporter($config);

$stmt = $pdo->prepare("SELECT * FROM user");
$stmt->execute();

$exporter->export('php://output', new PdoCollection($stmt));
```

### Export with CallbackCollection

[](#export-with-callbackcollection)

```
use Goodby\CSV\Export\Standard\Exporter;
use Goodby\CSV\Export\Standard\ExporterConfig;

use Goodby\CSV\Export\Standard\Collection\CallbackCollection;

$data = [];
$data[] = ['user', 'name1'];
$data[] = ['user', 'name2'];
$data[] = ['user', 'name3'];

$collection = new CallbackCollection($data, function($row) {
    // apply custom format to the row
    $row[1] = $row[1] . '!';

    return $row;
});

$config = new ExporterConfig();
$exporter = new Exporter($config);

$exporter->export('php://stdout', $collection);
```

### Export in Symfony2 action

[](#export-in-symfony2-action)

```
namespace AcmeBundle\ExampleBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\StreamedResponse;

class DefaultController extends Controller
{
	public function csvExportAction()
	{
		$conn = $this->get('database_connection');

		$stmt = $conn->prepare('SELECT * FROM somewhere');
		$stmt->execute();

		$response = new StreamedResponse();
		$response->setStatusCode(200);
		$response->headers->set('Content-Type', 'text/csv');
		$response->setCallback(function() use($stmt) {
			$config = new ExporterConfig();
			$exporter = new Exporter($config);

		    $exporter->export('php://output', new PdoCollection($stmt->getIterator()));
		});
		$response->send();

		return $response;
	}
}
```

License
-------

[](#license)

Csv is open-sourced software licensed under the MIT License - see the LICENSE file for details

Contributing
------------

[](#contributing)

We works under test driven development.

Checkout master source code from github:

```
hub clone goodby/csv
```

Install components via composer:

```
# If you don't have composer.phar
./scripts/bundle-devtools.sh .

# If you have composer.phar
composer.phar install --dev

```

Run phpunit:

```
./vendor/bin/phpunit
```

Acknowledgement
---------------

[](#acknowledgement)

Credits are found within composer.json file.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance52

Moderate activity, may be stable

Popularity52

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~431 days

Total

4

Last Release

340d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1698337?v=4)[Alexander Schranz](/maintainers/alexander-schranz)[@alexander-schranz](https://github.com/alexander-schranz)

---

Top Contributors

[![suin](https://avatars.githubusercontent.com/u/855338?v=4)](https://github.com/suin "suin (68 commits)")[![alexander-schranz](https://avatars.githubusercontent.com/u/1698337?v=4)](https://github.com/alexander-schranz "alexander-schranz (15 commits)")[![reoring](https://avatars.githubusercontent.com/u/735890?v=4)](https://github.com/reoring "reoring (10 commits)")[![zackkatz](https://avatars.githubusercontent.com/u/870979?v=4)](https://github.com/zackkatz "zackkatz (2 commits)")[![Richtermeister](https://avatars.githubusercontent.com/u/624921?v=4)](https://github.com/Richtermeister "Richtermeister (2 commits)")[![sasezaki](https://avatars.githubusercontent.com/u/42755?v=4)](https://github.com/sasezaki "sasezaki (2 commits)")[![hanneskaeufler](https://avatars.githubusercontent.com/u/68024?v=4)](https://github.com/hanneskaeufler "hanneskaeufler (1 commits)")[![IonBazan](https://avatars.githubusercontent.com/u/1985514?v=4)](https://github.com/IonBazan "IonBazan (1 commits)")[![iplesca](https://avatars.githubusercontent.com/u/5592031?v=4)](https://github.com/iplesca "iplesca (1 commits)")[![jared-fraser](https://avatars.githubusercontent.com/u/1113900?v=4)](https://github.com/jared-fraser "jared-fraser (1 commits)")[![ldimlight](https://avatars.githubusercontent.com/u/10096269?v=4)](https://github.com/ldimlight "ldimlight (1 commits)")[![maclof](https://avatars.githubusercontent.com/u/4358583?v=4)](https://github.com/maclof "maclof (1 commits)")[![mcdruid](https://avatars.githubusercontent.com/u/634209?v=4)](https://github.com/mcdruid "mcdruid (1 commits)")[![meonkeys](https://avatars.githubusercontent.com/u/50639?v=4)](https://github.com/meonkeys "meonkeys (1 commits)")[![nagodon](https://avatars.githubusercontent.com/u/604596?v=4)](https://github.com/nagodon "nagodon (1 commits)")[![obalais](https://avatars.githubusercontent.com/u/807362?v=4)](https://github.com/obalais "obalais (1 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (1 commits)")[![rene-roesch-blg](https://avatars.githubusercontent.com/u/33286651?v=4)](https://github.com/rene-roesch-blg "rene-roesch-blg (1 commits)")[![emmanuelgautier](https://avatars.githubusercontent.com/u/2765366?v=4)](https://github.com/emmanuelgautier "emmanuelgautier (1 commits)")[![cordoval](https://avatars.githubusercontent.com/u/328359?v=4)](https://github.com/cordoval "cordoval (1 commits)")

---

Tags

exportcsvimport

###  Code Quality

TestsPHPUnit

Static AnalysisRector

### Embed Badge

![Health badge](/badges/handcraftedinthealps-goodby-csv/health.svg)

```
[![Health](https://phpackages.com/badges/handcraftedinthealps-goodby-csv/health.svg)](https://phpackages.com/packages/handcraftedinthealps-goodby-csv)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

3.5k166.1M646](/packages/league-csv)[goodby/csv

CSV import/export library

9555.6M23](/packages/goodby-csv)[ufirst/lang-import-export

A Laravel package providing artisan commands to import and export language files from and to CSV.

42207.9k](/packages/ufirst-lang-import-export)[shuchkin/simplecsv

Parse and retrieve data from CSV files. Export data to CSV.

5192.4k](/packages/shuchkin-simplecsv)[highsolutions/laravel-lang-import-export

A Laravel package providing artisan commands to import and export language files from and to CSV.

25292.3k](/packages/highsolutions-laravel-lang-import-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
