PHPackages                             net\_bazzline/php\_component\_csv - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. net\_bazzline/php\_component\_csv

ActiveLibrary[File &amp; Storage](/categories/file-storage)

net\_bazzline/php\_component\_csv
=================================

free as in freedom php component to easy up usage (reading and writing) of csv files for php 5.6 and above

1.7.0(7y ago)81.1k3[2 issues](https://github.com/bazzline/php_component_csv/issues)1LGPL-3.0PHPPHP &gt;=5.6

Since May 17Pushed 7y ago5 watchersCompare

[ Source](https://github.com/bazzline/php_component_csv)[ Packagist](https://packagist.org/packages/net_bazzline/php_component_csv)[ RSS](/packages/net-bazzline-php-component-csv/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (24)Used By (1)

CSV Handling Component for PHP
==============================

[](#csv-handling-component-for-php)

This project aims to deliver an easy to use and free as in freedom php compontent for dealing with csv files (read and write).

This component is heavily influenced by [jwage/easy-csv](https://github.com/jwage/easy-csv). It was mainly created because of missing compatibility with php 5.6 and no official packagist support from [jwage/easy-csv](https://github.com/jwage/easy-csv).

The build status of the current master branch is tracked by Travis CI: [![Build Status](https://camo.githubusercontent.com/8a5b684b2df6d6c7d69238ec7ac4d5338c5064b4e6f79f5a7eda66e1019a2354/68747470733a2f2f7472617669732d63692e6f72672f62617a7a6c696e652f7068705f636f6d706f6e656e745f6373762e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/bazzline/php_component_csv)[![Latest stable](https://camo.githubusercontent.com/a9f13e925f08e988d448b0462a06e281d7dbc98c0c49c99116dfeab67e96534c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65745f62617a7a6c696e652f7068705f636f6d706f6e656e745f6373762e737667)](https://packagist.org/packages/net_bazzline/php_component_csv)

The scrutinizer status are: [![code quality](https://camo.githubusercontent.com/8bfdfc532732747b60ce62f0221f17ed39359e1b27cfb4af775151a649d4f147/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f62617a7a6c696e652f7068705f636f6d706f6e656e745f6373762f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/bazzline/php_component_csv/)

The versioneye status is: [![Dependency Status](https://camo.githubusercontent.com/845a40e12c4e5c0426021b89b72644eca0d9fdeff8057fa8d37a59391e403e49/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3535373439326231333136313337303030643030303064302f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/557492b1316137000d0000d0)

Take a look on [openhub.net](https://www.openhub.net/p/php_component_csv).

The current change log can be found [here](https://github.com/bazzline/php_component_csv/blob/master/CHANGELOG.md).

Benefits
========

[](#benefits)

- low and stable memory usage (give it a try by using [benchmarkReader](https://github.com/bazzline/php_component_csv/blob/master/example/benchmarkReader) and [benchmarkWriter](https://github.com/bazzline/php_component_csv/blob/master/example/benchmarkWriter))
- works with PHP 5.6 and above
- \_\_invoke() implemented to use it as function
- unified reader and writer
- adapter to easy up migration from [EasyCsv - 0.0.1](https://github.com/jwage/easy-csv/tree/0.0.1/lib/EasyCSV) to this component
    - [writer](https://github.com/jwage/easy-csv/blob/master/lib/EasyCSV/Writer.php)
    - [reader](https://github.com/jwage/easy-csv/blob/master/lib/EasyCSV/Reader.php)
- usage of [filters](https://github.com/bazzline/php_component_csv/blob/master/source/Net/Bazzline/Component/Csv/Filter) - control what comes in and what comes out
- reader
    - implemented iterator
    - readOne();
    - readMany();
    - readAll();
- writer
    - copy();
    - delete();
    - move();
    - truncate();
    - writeOne();
    - writeMany();
    - writeAll(); //truncates file and writes content

Install
=======

[](#install)

By Hand
-------

[](#by-hand)

```
mkdir -p vendor/net_bazzline/php_component_csv
cd vendor/net_bazzline/php_component_csv
git clone https://github.com/bazzline/php_component_csv .

```

With [Packagist](https://packagist.org/packages/net_bazzline/php_component_csv)
-------------------------------------------------------------------------------

[](#with-packagist)

```
composer require net_bazzline/php_component_csv:dev-master

```

Usage
=====

[](#usage)

[Reader](http://www.bazzline.net/55371e9f93dbdec83dc82730a5a73db5fc36272e/class-Net.Bazzline.Component.Csv.Reader.Reader.html)
------------------------------------------------------------------------------------------------------------------------------

[](#reader)

### Read Content

[](#read-content)

```
$reader = new Reader('my/file.csv');
//I am using json_encode() since there is no official and best way how to
// output arrays on the command line.

//read one line
echo json_encode($reader->readOne()) . PHP_EOL;

//read 10 lines
foreach ($reader->readMany(10) as $line) {
    echo json_encode($line) . PHP_EOL;
}

//read all lines
foreach ($reader->readAll() as $line) {
    echo json_encode($line) . PHP_EOL;
}
```

#### By Iteration

[](#by-iteration)

```
$reader = new Reader('my/file.csv');
//I am using json_encode() since there is no official and best way how to
// output arrays on the command line.

if ($reader->hasHeadline()) {
    echo 'headlines: ' . json_encode($reader->readHeadline());
}

foreach ($reader as $line) {
    echo json_encode($line) . PHP_EOL;
}
```

#### By Using As A Function

[](#by-using-as-a-function)

```
$reader = new Reader('my/file.csv');
//I am using json_encode() since there is no official and best way how to
// output arrays on the command line.

while ($line = $reader()) {
    echo json_encode($line) . PHP_EOL;
}
```

[Writer](http://www.bazzline.net/55371e9f93dbdec83dc82730a5a73db5fc36272e/class-Net.Bazzline.Component.Csv.Writer.Writer.html)
------------------------------------------------------------------------------------------------------------------------------

[](#writer)

### Write Content

[](#write-content)

#### By Iteration

[](#by-iteration-1)

```
//$headlines contains a php array
//$lines contains a php array of arrays
$writer = new Writer('my/file.csv');

$writer->writeHeadline($headlines);

foreach ($lines as $line) {
    $writer->writeOne($line);
}
```

#### At Once

[](#at-once)

```
//$headlines contains a php array
//$lines contains a php array of arrays
$writer = new Writer('my/file.csv');

$writer->writeHeadline($headlines);
$writer->writeMany($lines);
```

#### By Using As A Function

[](#by-using-as-a-function-1)

```
//$line contains a php array
//$lines contains a php array of arrays
$writer = new Writer('my/file.csv');

$writer($line);

foreach ($lines as $line) {
    $writer($line);
}
```

### Truncate

[](#truncate)

```
$writer = new Writer('my/file.csv');

$writer->truncate();
```

### Copy

[](#copy)

```
$writer = new Writer('my/file.csv');

$writer->copy('my/my_first_copy.csv');    //writer will still write into "file.csv"

$writer->copy('my/my_second_copy.csv', true);    //writer will write in "my_second_copy.csv"
```

### Move

[](#move)

```
$writer = new Writer('my/file.csv');

$writer->move('my/new_name.csv');   //writer will write in "new_name.csv"
```

API
===

[](#api)

[API](http://www.bazzline.net/55371e9f93dbdec83dc82730a5a73db5fc36272e/index.html) is available at [bazzline.net](http://www.bazzline.net).

Other Great Components
======================

[](#other-great-components)

- [goodby/csv](https://github.com/goodby/csv)
- [thephpleague/csv](https://github.com/thephpleague/csv)
- [keboola/php-csv](https://github.com/keboola/php-csv)
- [ajgarlag/AiglCsv](https://github.com/ajgarlag/AjglCsv)
- [jwage/easy-csv](https://github.com/jwage/easy-csv)
- [swt83/php-csv](https://github.com/swt83/php-csv)

Hall of Fame - The list of contributors
=======================================

[](#hall-of-fame---the-list-of-contributors)

- [peter279k](https://github.com/peter279k) - [homepage](https://peterli.website)
- [stevleibelt](https://github.com/stevleibelt) - [homepage](https://stev.leibelt.de)

Contributing
============

[](#contributing)

Please see [CONTRIBUTING](https://github.com/bazzline/php_component_csv/blob/master/CONTRIBUTING.md) for details.

Final Words
===========

[](#final-words)

Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it. [Donate something](https://gratipay.com/~stevleibelt) if you love it :-\].

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 98.1% 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 ~57 days

Recently: every ~255 days

Total

23

Last Release

2794d ago

Major Versions

0.2.0 → 1.0.02015-06-07

PHP version history (2 changes)0.1.0PHP &gt;=5.3.3

1.7.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/58451b041f6f5a38c7e62762c96d01f5e2bcac30e322707fe4760a82bccb6856?d=identicon)[artodeto](/maintainers/artodeto)

---

Top Contributors

[![stevleibelt](https://avatars.githubusercontent.com/u/2287220?v=4)](https://github.com/stevleibelt "stevleibelt (105 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")

---

Tags

psrphpfilesysteminvokeexportcsvmemoryiteratoradapterfilterimportreadwritecomponentbazzlinelgplfree as in freedomPSR-4reusablePHP7easyheadlineusageeasycsvtranversablelowphp56

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/net-bazzline-php-component-csv/health.svg)

```
[![Health](https://phpackages.com/badges/net-bazzline-php-component-csv/health.svg)](https://phpackages.com/packages/net-bazzline-php-component-csv)
```

###  Alternatives

[league/csv

CSV data manipulation made easy in PHP

3.5k182.1M861](/packages/league-csv)[openspout/openspout

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

1.2k70.2M243](/packages/openspout-openspout)[shuchkin/simplecsv

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

52100.9k](/packages/shuchkin-simplecsv)

PHPackages © 2026

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