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

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

gugglegum/csv-rw
================

CSV reader and writer

0.9.8(6y ago)2197MITPHPPHP &gt;=7.0.0

Since Nov 22Pushed 4y ago2 watchersCompare

[ Source](https://github.com/gugglegum/csv-rw)[ Packagist](https://packagist.org/packages/gugglegum/csv-rw)[ RSS](/packages/gugglegum-csv-rw/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (9)DependenciesVersions (10)Used By (0)

CSV Reader &amp; Writer
=======================

[](#csv-reader--writer)

This is easy to use Composer package to read and write CSV files in very convenient way. The CSV Reader is actually an OO-wrapper on the `fgetcsv()` built-in PHP function. It adds exceptions on errors and implements `Iterator` interface. You can iterate CSV reader in `foreach` statement like array. It supports headers of columns, so you may handle with associative data arrays. Headers may be read from first line of CSV file or be set manually. Or be read from first line and then changed by some reflection function or whatever you want.

Instead of opening you also can assign already opened file handle or stream. This package contains validation of data consistency. For example, it throws an exception if some row contains less or more columns than previous one. Therefore you don't need to always check type of return values. Just use `try .. catch` statement and catch exceptions if necessary. The package uses strong typing for scalars came to us from PHP7.

Usage
-----

[](#usage)

See more examples of usage in `/test` folder.

### Read CSV

[](#read-csv)

```
use \gugglegum\CsvRw\CsvReader;
use \gugglegum\CsvRw\CsvFormat;

$csv = new CsvReader(new CsvFormat([
    'delimiter' => ',',
    'enclosure' => '"',
    'escape' => '\\',
]));
$csv->open('input.csv', CsvReader::WITH_HEADERS);

foreach ($csv as $row) {
    var_dump($row);
}

$csv->close();
```

### Write CSV

[](#write-csv)

```
use gugglegum\CsvRw\CsvFormat;
use gugglegum\CsvRw\CsvWriter;

$headers = ['id', 'firstName', 'lastName'];

$rows = [
    [
        'id' => 1,
        'firstName' => 'John',
        'lastName' => 'Smith',
    ],
];

$csv = new CsvWriter(new CsvFormat([
   'delimiter' => ',',
   'enclosure' => '"',
   'escape' => '\\',
]));

$csv->open('output.csv', CsvWriter::WITH_HEADERS, $headers);

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

$csv->close();
```

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

[](#installation)

This library is available as composer package. To start using composer in your project follow these step

### Install Composer

[](#install-composer)

```
curl -s http://getcomposer.org/installer | php
mv ./composer.phar ~/bin/composer # or /usr/local/bin/composer

```

### Install this package

[](#install-this-package)

```
composer require gugglegum/csv-rw

```

### Add composer's autoloader to you code

[](#add-composers-autoloader-to-you-code)

```
require 'vendor/autoload.php';

```

Now you can use CSV reader &amp; writer in your code.

Troubleshooting
---------------

[](#troubleshooting)

If you have troubles with MAC's line-endings `\r`, you may turn on PHP option `auto_detect_line_endings`:

> When turned on, PHP will examine the data read by fgets() and file() to see if it is using Unix, MS-Dos or Macintosh line-ending conventions.

It may be turned on from you PHP code. Just add this before reading MAC files:

```
ini_set('auto_detect_line_endings', true);
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 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 ~144 days

Recently: every ~246 days

Total

9

Last Release

2348d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c7fbb933ba217a413e632183e6061f81bd1d285bb86efa82289977038577d88?d=identicon)[gugglegum](/maintainers/gugglegum)

---

Top Contributors

[![gugglegum](https://avatars.githubusercontent.com/u/1580712?v=4)](https://github.com/gugglegum "gugglegum (19 commits)")

---

Tags

parsercsvwriterreader

### Embed Badge

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

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

###  Alternatives

[shuchkin/simplexlsx

Parse and retrieve data from Excel XLSx files. MS Excel 2007 workbooks PHP reader.

1.8k4.0M26](/packages/shuchkin-simplexlsx)[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

561606.4k1](/packages/faisalman-simple-excel-php)[avadim/fast-excel-reader

Lightweight and very fast XLSX Excel Spreadsheet and CSV Reader in PHP

106693.8k9](/packages/avadim-fast-excel-reader)[csanquer/colibri-csv

Lightweight and performant CSV reader and writer library

16163.7k5](/packages/csanquer-colibri-csv)[rodenastyle/stream-parser

PHP Multiformat Streaming Parser

447202.3k2](/packages/rodenastyle-stream-parser)[akeneo-labs/spreadsheet-parser

Akeneo Spreadsheet parser. Reads XLXS files from Microsoft Excel and Open Office

145608.4k6](/packages/akeneo-labs-spreadsheet-parser)

PHPackages © 2026

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