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

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

atk14/csv-reader
================

Reads CSV data from a file or a string, detects automatically CSV format parameters

v1.1.2(1y ago)029.3k↓54.5%3MITPHPPHP &gt;=5.6.0

Since Oct 10Pushed 11mo ago2 watchersCompare

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

READMEChangelogDependencies (1)Versions (7)Used By (3)

CsvReader
=========

[](#csvreader)

[![Build Status](https://camo.githubusercontent.com/0bd50cc7e74adfe138c4af89ac6868abb903344b7c5ded4a46a3dfd2c18e45d7/68747470733a2f2f6170702e7472617669732d63692e636f6d2f61746b31342f4373765265616465722e7376673f746f6b656e3d4b63375578674b356f71464738735a4168437a67266272616e63683d6d6173746572)](https://app.travis-ci.com/atk14/CsvReader)

Reads CSV data from a file or a string. Detects automatically CSV format parameters.

Basic usage
-----------

[](#basic-usage)

```
$csv_data = '
k1;k2;k3
v1;v2;v3
x1;x2;x3
y1;y2
z1
';
$csv_data = trim($csv_data);

$reader = CsvReader::FromData($csv_data);
// or
$reader = CsvReader::FromFile("path/to/file.csv");

$reader->getRowCount(); // 5
$reader->getColumnCount(); // 3

$rows = $reader->getRows();
// [
//  ["k1","k2","k3"],
//  ["v1","v2","v3"],
//  ["x1","x2","x3"],
//  ["y1","y2",""],
//  ["z1","",""],
// ]

$rows = $reader->getRows(["offset" => 2]);
// [
//  ["x1","x2","x3"],
//  ["y1","y2",""],
//  ["z1","",""],
// ]

$row = $reader->getRow(0);
// ["k1","k2","k3"]

$row = $reader->getRow(1);
// ["v1","v2","v3"]

$col = $reader->getColumn(0);
// ["k1","v1","x1","y1","z1"],

$col = $reader->getColumn(0,["offset" => 1]);
// ["v1","x1","y1","z1"],

$col = $reader->getColumn(2);
// ["k3","v3","x3","",""],

$col = $reader->getColumn(3);
// []

$rows = $reader->getAssociativeRows();
// [
//  ["k1" => "v1", "k1" => "v2", "k3" => "v3"],
//  ["k1" => "x1", "k1" => "x2", "k3" => "x3"],
//  ["k1" => "y1", "k1" => "y2", "k3" => ""],
//  ["k1" => "z1", "k1" => "", "k3" => ""],
// ]

$rows = $reader->getAssociativeRows(["header_line" => 1]); // counting from 0, so this is the 2nd line
// [
//  ["v1" => "x1", "v1" => "x2", "v3" => "x3"],
//  ["v1" => "y1", "v1" => "y2", "v3" => ""],
//  ["v1" => "z1", "v1" => "", "v3" => ""],
// ]

$rows = $reader->getAssociativeRows(["keys" => ["f1","f2","f3"]]);
// [
//  ["f1" => "k1", "k1" => "k2", "k3" => "k3"],
//  ["f1" => "v1", "k1" => "v2", "k3" => "v3"],
//  ["f1" => "x1", "k1" => "x2", "k3" => "x3"],
//  ["f1" => "y1", "k1" => "y2", "k3" => ""],
//  ["f1" => "z1", "k1" => "", "k3" => ""],
// ]

$rows = $reader->getAssociativeRows(["keys" => ["f1","f2","f3"], "offset" => 2]);
// [
//  ["f1" => "x1", "k1" => "x2", "k3" => "x3"],
//  ["f1" => "y1", "k1" => "y2", "k3" => ""],
//  ["f1" => "z1", "k1" => "", "k3" => ""],
// ]

```

CSV format parameters auto-detection
------------------------------------

[](#csv-format-parameters-auto-detection)

The CsvReader detects format parameters automatically. If the auto-detection fails, format parameters can be specified explicitly.

```
$reader = CsvReader::FromData($csv_data,[
  "delimiter" => ";",
  "quote" => "'"
]);
// or
$reader = CsvReader::FromFile("path/to/file.csv",[
  "delimiter" => ";",
  "quote" => "'"
]);

```

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

[](#installation)

```
composer require atk14/cvs-reader

```

Testing
-------

[](#testing)

```
composer update --dev
./vendor/bin/run_unit_tests test

```

License
-------

[](#license)

CsvReader is free software distributed [under the terms of the MIT license](http://www.opensource.org/licenses/mit-license)

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance44

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community13

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

Total

5

Last Release

601d ago

PHP version history (2 changes)v1.0PHP &gt;=5.6.0

v1.0.1PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/974278?v=4)[Jaromir Tomek](/maintainers/yarri)[@yarri](https://github.com/yarri)

---

Top Contributors

[![yarri](https://avatars.githubusercontent.com/u/974278?v=4)](https://github.com/yarri "yarri (49 commits)")

---

Tags

csv

### Embed Badge

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

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k152.8M847](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

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

Fast Excel import/export for Laravel

2.3k26.3M50](/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.5M209](/packages/openspout-openspout)[goodby/csv

CSV import/export library

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

Lightweight Exporter library

44121.3M37](/packages/sonata-project-exporter)

PHPackages © 2026

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