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

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

phpexperts/csv-speaker
======================

A quick and easy package for easily reading and writing CSV to/from strings and arrays.

v1.4.0(1y ago)62.2k2MITPHPPHP &gt;=7.4CI failing

Since Apr 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/phpexpertsinc/CSVSpeaker)[ Packagist](https://packagist.org/packages/phpexperts/csv-speaker)[ Docs](https://www.phpexperts.pro/)[ RSS](/packages/phpexperts-csv-speaker/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

CSVSpeaker
==========

[](#csvspeaker)

[![TravisCI](https://camo.githubusercontent.com/e7f541d53cd7f08b75ddb1fb2ff6a8b14d3365c10f017c15fc7c472a162ec705/68747470733a2f2f7472617669732d63692e6f72672f70687065787065727473696e632f435356537065616b65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpexpertsinc/CSVSpeaker)[![Maintainability](https://camo.githubusercontent.com/8452a2625605ae5a4a5e06a086949d382c4f27555dab71d68dd2ac58f4d421f8/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f37386638343964376264636361393965623732302f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phpexpertsinc/CSVSpeaker/maintainability)[![Test Coverage](https://camo.githubusercontent.com/6afe902fdf052124d497d1872a6522a6a84f1a1fe72d7b2c7230b42a394b4bd0/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f37386638343964376264636361393965623732302f746573745f636f766572616765)](https://codeclimate.com/github/phpexpertsinc/CSVSpeaker/test_coverage)

CSVSpeaker is a PHP Experts, Inc., Project for easily converting CSV to/from arrays.

This library's main goal is to make it drop-dead simple to get an array from a CSV string, and also vice versa.

**Special Note:** This project has been updated to support the deprecation of `fgetcsv` and `fputcsv`'s `$enclosure` parameter.

See [**CSV and PHP 8.4+**](http://archive.today/2024.08.23-131404/https://nyamsprod.com/blog/csv-and-php8-4/)for details.

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

[](#installation)

Via Composer

```
composer require phpexperts/csv-speaker
```

Usage
-----

[](#usage)

### Reading

[](#reading)

#### Instantiating / Loading

[](#instantiating--loading)

```
    // The CSVReader can be instantiated from a file via just the file's filename:
    $csvReader = CSVReader::fromFile('/tmp/my.csv');

    // or via a SplFileObject:
    $csvReader = CSVReader::fromFile(new SplFileObject('/tmp/my.csv'));

    // More simply, you can instantiate from any CSV string.
    $csvReader = CSVReader::fromString('a,b,c,d');
```

#### Convert To An array

[](#convert-to-an-array)

```
    $output = $csvReader->toArray();
    /* [
        ['a', 'b', 'c', 'd']
    ] */
```

#### The First Row becomes the Array Keys, by Default

[](#the-first-row-becomes-the-array-keys-by-default)

```
    $csv =  'Galt', 'Age' => 37]
    ] */
```

#### You can also turn off headers:

[](#you-can-also-turn-off-headers)

```
    $csv = addRow($input[0]);
    $csvWriter->addRow($input[1]);
    $csv = $csvWriter->getCSV();

    /* csv:
        a,b,c
        d,e,f
    */
```

#### Keyed Arrays (Hashmaps)

[](#keyed-arrays-hashmaps)

```
    $input = [
        ['Name' => 'John Galt', 'Age' => 37],
        ['Name' => 'Mary Jane', 'Age' => 27],
    ];
    $csvWriter = new CSVWriter();
    $csvWriter->addRow($input[0]);
    $csvWriter->addRow($input[1]);
    $csv = $csvWriter->getCSV();

    /* csv:
        Name,Age
        "John Galt",37
        "Mary Jane",27
    */
```

Use cases
=========

[](#use-cases)

PHPExperts\\CSVSpeaker\\CSVReader
✔ Will convert a csv string to an array
✔ Will output a csv file to an array
✔ Will use the first row as array keys by default
✔ Can be loaded via a file name
✔ Throw an exception when given an invalid file type
✔ Will return an empty array if input is not proper csv

PHPExperts\\CSVSpeaker\\CSVWriter
✔ Converts a simple array to csv
✔ Can append rows to existing csv
✔ Will set keys as header row
✔ Can add multiple rows with the same header
✔ Will gracefully ignore empty arrays

ChangeLog
---------

[](#changelog)

Please see the [changelog](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
phpunit
```

Contributors
============

[](#contributors)

[Theodore R. Smith](https://www.phpexperts.pro/%5D)
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.

License
-------

[](#license)

MIT license. Please see the [license file](LICENSE) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

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

Total

5

Last Release

677d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.1

v1.4.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f3a2dd16766f6b03c330e65aaca9dfb97f1bbbb41c5e2af5681f58f670b7917?d=identicon)[hopeseekr](/maintainers/hopeseekr)

---

Top Contributors

[![hopeseekr](https://avatars.githubusercontent.com/u/1125541?v=4)](https://github.com/hopeseekr "hopeseekr (16 commits)")

---

Tags

csvSimpleeasy

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.9k157.3M852](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

3.5k176.5M816](/packages/league-csv)[rap2hpoutre/fast-excel

Fast Excel import/export for Laravel

2.3k26.3M51](/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.2k65.5M217](/packages/openspout-openspout)[goodby/csv

CSV import/export library

9865.7M25](/packages/goodby-csv)[sonata-project/exporter

Lightweight Exporter library

44921.6M39](/packages/sonata-project-exporter)

PHPackages © 2026

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