PHPackages                             mmerian/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. mmerian/csv

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

mmerian/csv
===========

A library for easily reading and writing CSV files

1.0.10(10y ago)59.5k↓50%2[2 issues](https://github.com/mmerian/csv/issues)MITPHPPHP &gt;= 5.3.0

Since Sep 10Pushed 10y ago2 watchersCompare

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

READMEChangelogDependenciesVersions (9)Used By (0)

csv
===

[](#csv)

[![Build Status](https://camo.githubusercontent.com/1c8bc565eae0b8fb3bc6f6d62c2b432cad8fb603fc8779cc1d5e475da5cf3e47/68747470733a2f2f7472617669732d63692e6f72672f6d6d657269616e2f6373762e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mmerian/csv)[![Latest Stable Version](https://camo.githubusercontent.com/912960f25d5bdee9093d1fcde238fe3bb1f79b7e264a4007afbb40c50908be82/68747470733a2f2f706f7365722e707567782e6f72672f6d6d657269616e2f6373762f762f737461626c65)](https://packagist.org/packages/mmerian/csv) [![Total Downloads](https://camo.githubusercontent.com/de876795f73c205dec1b41a353e9869973aec43bf3092ac8bda446c453e0e95d/68747470733a2f2f706f7365722e707567782e6f72672f6d6d657269616e2f6373762f646f776e6c6f616473)](https://packagist.org/packages/mmerian/csv) [![Latest Unstable Version](https://camo.githubusercontent.com/acef8e4ca9e7e0bc4a08fcaa02ef6f1316b96ee9ef483bde513c103d99cb9c1b/68747470733a2f2f706f7365722e707567782e6f72672f6d6d657269616e2f6373762f762f756e737461626c65)](https://packagist.org/packages/mmerian/csv) [![License](https://camo.githubusercontent.com/67cbef4e99ba8929779cbdafeb08db40ac23437d7ee1d1e645f17bf95c6b6b9c/68747470733a2f2f706f7365722e707567782e6f72672f6d6d657269616e2f6373762f6c6963656e7365)](https://packagist.org/packages/mmerian/csv)

This library is designed to help you read and write csv files.

Usage
-----

[](#usage)

### Reading CSV files

[](#reading-csv-files)

Say you have a CSV file that looks like this :

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

```

Instanciating the reader is really easy :

```
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 :

- `'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

[](#automatic-field-processing)

The reader is also able to apply formatting functions to your CSV fields.

```
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
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~130 days

Total

8

Last Release

3717d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/63762af14ad1732ff53b3ed9189f7127de366d04a240dcbb49e08bf1280c7317?d=identicon)[mmerian](/maintainers/mmerian)

---

Top Contributors

[![mmerian](https://avatars.githubusercontent.com/u/167871?v=4)](https://github.com/mmerian "mmerian (12 commits)")

---

Tags

processingdatacsv

### Embed Badge

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

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

###  Alternatives

[sonata-project/exporter

Lightweight Exporter library

44920.9M35](/packages/sonata-project-exporter)[soapbox/laravel-formatter

A formatting library that converts data output between XML, CSV, JSON, TXT, YAML and a few others.

2501.1M12](/packages/soapbox-laravel-formatter)[burnbright/silverstripe-importexport

An upgrade to SilverStripe's bulk loading and exporting

4534.1k1](/packages/burnbright-silverstripe-importexport)[akeneo-labs/data-generator-bundle

Akeneo PIM Bundle to generate data in order to test high volume operations

112.1k](/packages/akeneo-labs-data-generator-bundle)

PHPackages © 2026

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