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

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

jabranr/csv-parser
==================

Parse CSV data from a file, stream or string

3.0.0(7y ago)935.3k↑22.5%6[5 issues](https://github.com/jabranr/csv-parser/issues)1MIT LicensePHPPHP &gt;=7.0

Since Mar 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/jabranr/csv-parser)[ Packagist](https://packagist.org/packages/jabranr/csv-parser)[ Docs](https://github.com/jabranr/csv-parser)[ RSS](/packages/jabranr-csv-parser/feed)WikiDiscussions develop Synced 1w ago

READMEChangelog (2)Dependencies (1)Versions (11)Used By (1)

CSV Parser (PHP) [![Build Status](https://camo.githubusercontent.com/45ff66b621356755168b5806f884c37251aff669c8c23f67e5655dafaa52dbed/68747470733a2f2f7472617669732d63692e6f72672f6a616272616e722f6373762d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jabranr/csv-parser) [![Latest Stable Version](https://camo.githubusercontent.com/4cd103a264734e9f8d52f72e974d68be1caa453a8440a4d5de5a4a512703efa0/68747470733a2f2f706f7365722e707567782e6f72672f6a616272616e722f6373762d7061727365722f762f737461626c652e737667)](https://packagist.org/packages/jabranr/csv-parser) [![Total Downloads](https://camo.githubusercontent.com/25e0f3447a6db5fe75d1ab1e76a810aff11d77084a10a4224bd17a9551a93a57/68747470733a2f2f706f7365722e707567782e6f72672f6a616272616e722f6373762d7061727365722f646f776e6c6f6164732e737667)](https://packagist.org/packages/jabranr/csv-parser)
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#csv-parser-php----)

PHP client to parse CSV data from a path, file, stream, resource or string into indexed or associative arrays.

#### Migration from v2 to v3

[](#migration-from-v2-to-v3)

PHP support updated to 7+

Install
=======

[](#install)

Install using [composer](http://getcomposer.org)

```
#composer.json

{
  "require": {
    "jabranr/csv-parser": "^3.0"
  }
}
```

Run following to install

```
$ comsposer install
```

Use
===

[](#use)

Initiate a new instance

```
$csv = new Jabran\CSV_Parser();
```

Unit tests
==========

[](#unit-tests)

If you have `composer` installed globally then:

Run unit tests

```
$ cd path/to/csv-parser
$ composer run tests
```

If you have `phpunit` installed globally then:

```
$ cd path/to/csv-parser
$ phpunit
```

API
===

[](#api)

Get data from a string

```
/* @param: string $str */
$csv->fromString($str);
```

Get data from a resource (Since v2.0.2)

```
/* @param: resource $resource (f.e. resource created using fopen()) */
$csv->fromResource($resource);
```

Get data from a path/URL (Since v2.0.2)

```
/* @param: string $path */
$csv->fromPath($path);
```

Parse data for output

```
/**
 * Set $headers true/false to include top/first row
 * and output an associative array
 *
 * @param: boolean $headers (Default: true)
 * @return: array
 */
$csv->parse($headers);
```

More useful methods (Since v2.0.2)

```
/**
 * Set columns
 * @param array $columns
 * @return Jabran\CSV_Parser
 */
$csv->setColumns($columns);

/**
 * Set rows
 * @param array $rows
 * @return Jabran\CSV_Parser
 */
$csv->setRows($rows);

/**
 * Set headers
 * @param array $headers
 * @return Jabran\CSV_Parser
 */
$csv->setHeaders($headers);

/**
 * Get columns
 * @return array
 */
$csv->getColumns();

/**
 * Get rows
 * @return array
 */
$csv->getRows();

/**
 * Get headers
 * @return array
 */
$csv->getHeaders();
```

Example
=======

[](#example)

Example input string

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

$csv = new Jabran\CSV_Parser;

$str = 'id,first_name,last_name;1,Jabran,Rafique';

$csv->fromString($str);

// Output with headers:
$csv->parse();

Array(
  [id] => 1,
  [first_name] => 'Jabran',
  [last_name] => 'Rafique'
)

// Output without headers:
$csv->parse(false);

Array(
  [0] => array(
    [0] => 'id',
    [1] => 'first_name',
    [2] => 'last_name'
 ),
  [1] => array(
    [0] => 1,
    [1] => 'Jabran',
    [2] => 'Rafique'
 )
)
```

License
=======

[](#license)

© 2015 onwards

MIT License - [Jabran Rafique](http://jabran.me)

[![Analytics](https://camo.githubusercontent.com/5845e8d0b8a7136eba289344e68f8dfb8e68b5b92ff6988924ae8286aa2db2cf/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d35303638383835312d312f6373762d706172736572)](https://github.com/igrigorik/ga-beacon)

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance9

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community12

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

Recently: every ~295 days

Total

9

Last Release

2654d ago

Major Versions

1.0.1 → 2.0.12015-04-07

2.1.1 → 3.0.02019-03-04

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

3.0.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2131246?v=4)[Jabran Rafique](/maintainers/jabranr)[@jabranr](https://github.com/jabranr)

---

Top Contributors

[![jabranr](https://avatars.githubusercontent.com/u/2131246?v=4)](https://github.com/jabranr "jabranr (42 commits)")

---

Tags

csvparserphpphpparsercsv

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[openspout/openspout

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

1.2k65.5M205](/packages/openspout-openspout)[avadim/fast-excel-reader

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

105693.8k9](/packages/avadim-fast-excel-reader)[shuchkin/simplecsv

Parse and retrieve data from CSV files. Export data to CSV.

5198.0k](/packages/shuchkin-simplecsv)[csanquer/colibri-csv

Lightweight and performant CSV reader and writer library

16163.7k5](/packages/csanquer-colibri-csv)

PHPackages © 2026

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