PHPackages                             seankndy/phpcsv - 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. seankndy/phpcsv

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

seankndy/phpcsv
===============

PHP package for working with CSV data

v1.1.0(7y ago)026PHPPHP &gt;=7.1.0

Since May 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/seankndy/phpcsv)[ Packagist](https://packagist.org/packages/seankndy/phpcsv)[ RSS](/packages/seankndy-phpcsv/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (12)Used By (0)

phpcsv is a small PHP package to assist in dealing with CSV data.

It is not meant to be full-featured or very high-performance. I regularly need to manipulate one-off CSV data and so I built this to assist in the common things I keep re-writing like formatting a date or merging 2 CSVs together.

A few examples:

Selectively join data from one CSV into another.

This would look at the 'id' column in file.csv and match it with 'fid' column in other\_file.csv then take the 'username' column from other\_file.csv and fill it into the 'user' column of file.csv. then dump changes to stdout.

It is similar to an SQL join, for example: select file.\*, other\_file.username from file left join other\_file on file.id = other\_file.fid

```
use SeanKndy\CSV\CSV;

$csv = new CSV('file.csv');
$csv->join(
    new CSV('other_file.csv'),
    function ($r1, $r2) {
        return ($r1->get('id') == $r2->get('fid'));
    },
    ['user'],
    ['username']
));
$csv->getRecords()->dump();

```

Format a date column, dump output:

```
use SeanKndy\CSV\CSV;
use SeanKndy\CSV\Formatters;

$csv = new CSV('file.csv');
$csv->setFormatter('date_of_birth', function($data) {
    return Formatters::date($data, 'm/d/Y');
});
$csv->getRecords()->dump();

```

Loop through file without loading into memory:

```
use SeanKndy\CSV\CSV;

foreach (new CSV('file.csv', ['preload' => false])->getRecords() as $record) {
    print_r($record->getAll());
}

```

Selectively print columns in arbitrary order:

```
use SeanKndy\CSV\CSV;

$csv = new CSV('file.csv');
$csv->getRecords()->pickyDump(['age','dob','name','sex']);

```

Merge 2 columns together, separate by space. print changes to stdout

```
use SeanKndy\CSV\CSV;

$csv = new CSV('file.csv');
$csv->combineColumns(['first_name','last_name'], 'name');
$csv->getRecords()->dump();

```

Manually get or set data from a record. Note that this only works if you're NOT using mutators! If mutators are in use, then get() will return a clone/copy of that data post-mutated.

```
use SeanKndy\CSV\CSV;

$csv = new CSV('file.csv');
foreach ($csv->getRecords() as $record) {
    $age = $record->get('age');
    if ($age >= 18) {
        $record->set('is_adult', 'yes');
    }
}

```

Filter records (in this case, any record where 'sex' column is not 'male' would be removed):

```
use SeanKndy\CSV\CSV;

$csv = new CSV('file.csv');
$csv->getRecords()->filter(['sex' => 'male'])->dump();

```

Example of adding a custom Mutator to manipulate some data in records. In this case, we make sure the comma-separate Rate Group(s) column is paired with the same number of Billing Frequency items:

```
use SeanKndy\CSV\CSV;
use SeanKndy\CSV\Record;
use SeanKndy\CSV\Mutators\Mutator;

$csv = new CSV('customers.csv');
$csv->addMutator(new class extends Mutator {
    public function mutate(Record $record) {
        $rateGroups = preg_split('/,\s*/', $record->get('Rate Group(s)'));
        $billingFrequency = preg_split('/,\s*/', $record->get('Billing Frequency');

        if (count($rateGroups) > count($billingFrequency)) {
            // ex: if Rate Group(s) is '500,501,502' and Billing Frequency is '12'
            // then this would update Billing Frequency to be '12,12,12' to pair
            // with each of the Rate Group(s)
            for ($i = count($billingFrequency); $i < count($rateGroups); $i++) {
                $billingFrequency[] = $billingFrequency[0];
            }
            $record->set('Billing Frequency', implode(',', $billingFrequency));
        } else if (count($rateGroups) < count($billingFrequency)) {
            $billingFrequency = array_splice($billingFrequency, count($rateGroups));
            $record->set('Billing Frequency', implode(',', $billingFrequency));
        }

        return $record;
    }
});

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

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

Recently: every ~12 days

Total

11

Last Release

2625d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18705808?v=4)[Sean Kennedy](/maintainers/seankndy)[@seankndy](https://github.com/seankndy)

---

Top Contributors

[![seankndy](https://avatars.githubusercontent.com/u/18705808?v=4)](https://github.com/seankndy "seankndy (72 commits)")

---

Tags

csvcsv-dataphpcsvcomma separated value

### Embed Badge

![Health badge](/badges/seankndy-phpcsv/health.svg)

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

###  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)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k24.9M47](/packages/rap2hpoutre-fast-excel)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M131](/packages/openspout-openspout)[goodby/csv

CSV import/export library

9555.6M23](/packages/goodby-csv)[sonata-project/exporter

Lightweight Exporter library

44920.9M35](/packages/sonata-project-exporter)

PHPackages © 2026

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