PHPackages                             spyrit/light-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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. spyrit/light-csv

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

spyrit/light-csv
================

Spyrit Light CSV reader and writer library

1.1(12y ago)22.4k1LGPL-3.0+PHPPHP &gt;=5.3.3

Since Apr 10Pushed 12y ago9 watchersCompare

[ Source](https://github.com/spyrit/LightCsv)[ Packagist](https://packagist.org/packages/spyrit/light-csv)[ RSS](/packages/spyrit-light-csv/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (0)

Spyrit LightCSV
===============

[](#spyrit-lightcsv)

[![Latest Stable Version](https://camo.githubusercontent.com/cb9de5853bcde3e431c22731d96ccf35351d7bba488e9528dae0a1dfa4fb7bab/68747470733a2f2f706f7365722e707567782e6f72672f7370797269742f6c696768742d6373762f762f737461626c652e706e67)](https://packagist.org/packages/spyrit/light-csv)[![Latest Unstable Version](https://camo.githubusercontent.com/0d577165963492244b56b0d89e9f05c3b34bcb6324db71225f88c2d71148e3b6/68747470733a2f2f706f7365722e707567782e6f72672f7370797269742f6c696768742d6373762f762f756e737461626c652e706e67)](https://packagist.org/packages/spyrit/light-csv)[![Build Status](https://camo.githubusercontent.com/a607df93ebf06ccc0587076e308bec8fe4410ba0050154e55782c924579f8d3d/68747470733a2f2f7472617669732d63692e6f72672f7370797269742f4c696768744373762e706e67)](https://travis-ci.org/spyrit/LightCsv)

A light and simple CSV Reader/Writer PHP 5.3 Library. Fully Tested, very memory efficient and able to parse/write CSV files that weigh 100 Mb.

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

[](#installation)

- get composer  and install dependencies

```
curl -s https://getcomposer.org/installer | php
```

- add "[https://packagist.org/packages/spyrit/light-csv](spyrit/light-csv)" package to your composer.json file require section

```
php composer.phar require spyrit/light-csv:1.0.*
```

- install dependencies

```
php composer.phar install
```

- include vendor/autoload.php

How To
------

[](#how-to)

\###Read

Instanciate a new CSVReader with the following CSV parameters:

- field delimiter (default for Excel = ; )
- field enclosure character (default for Excel = " )
- character encoding = (default for Excel = CP1252 )
- end of line character (default for Excel = "\\r\\n" )
- escape character (default for Excel = "\\" )
- UTF8 BOM (default false) force removing BOM
- transliteration (default for Excel = null ) available options : 'translit', 'ignore', null
- force encoding detection (default for Excel = false )
- skip empty lines (default for Excel = false ) lines which all values are empty
- trim (default = false for Excel) trim all values

```
use Spyrit\LightCsv\CsvReader;

// create the reader
$reader = new CsvReader(array(
    'delimiter' => ';',
    'enclosure' => '"',
    'encoding' => 'CP1252',
    'eol' => "\r\n",
    'escape' => "\\",
    'bom' => false,
    'translit' => 'translit',
    'force_encoding_detect' => false,
    'skip_empty' => false,
    'trim' => false,
));

//Open the csv file to read
$reader->open('test.csv');

//Read each row
foreach ($reader as $row) {
    // do what you want with the current row array : $row
}

//close the csv file
$reader->close();
```

\###Write

Instanciate a new CSVWriter with the following CSV parameters:

- field delimiter (default for Excel = ; )
- field enclosure character (default for Excel = " )
- character encoding = (default for Excel = CP1252 )
- end of line character (default for Excel = "\\r\\n" )
- escape character (default for Excel = "\\" )
- enclosing\_mode (default = 'minimal'), possible values :
    - all : always enclose string
    - minimal : enclose string only if the delimiter, enclosure or line ending character is present
    - nonumeric : enclose string only if the value is non numeric (other character than digits and dot)
- escape\_double (default = true) if true double the enclosure to escape it, else escape it with escape character
- UTF8 BOM (default false) force writing BOM if encoding is UTF-8
- transliteration (default for Excel = null ) available options : 'translit', 'ignore', null
- trim (default = false for Excel) trim all values

```
use Spyrit\LightCsv\CsvWriter;

// create the writer
$writer = new CsvWriter(array(
    'delimiter' => ';',
    'enclosure' => '"',
    'encoding' => 'CP1252',
    'enclosing_mod' => 'minimal',
    'escape_double' => true,
    'eol' => "\r\n",
    'escape' => "\\",
    'bom' => false,
    'translit' => 'translit',
    'trim' => false,
));

//Open the csv file to write
$writer->open('test.csv');

//Write a row
$writer->writeRow(array('a', 'b', 'c'));

//Write multiple rows at the same time
$writer->writeRows(array(
    array('d', 'e', 'f'),
    array('g', 'h', 'i'),
    array('j', 'k', 'l'),
));

//close the csv file
$writer->close();
```

### Configuration : Dialect class

[](#configuration--dialect-class)

Instead of giving directly an array to the CsvReader or CsvWriter constructor, you can create a Dialect object, use setter methods to change parameters and pass it to the CsvReader (or CsvWriter) :

*Be careful, the options 'force\_encoding\_detect', 'skip\_empty' and 'trim' decrease significantly the performances*

```
use Spyrit\LightCsv\Dialect;
use Spyrit\LightCsv\CsvReader;
use Spyrit\LightCsv\CsvWriter;

// create a dialect with some CSV parameters
$dialect = new Dialect(array(
    'delimiter' => ';',
    'enclosure' => '"',
    'enclosing_mode' => 'minimal',
    'encoding' => 'CP1252',
    'eol' => "\r\n",
    'escape' => "\\",
    'escape_double' => true,
    'bom' => false,
    'translit' => 'translit',
    'force_encoding_detect' => false,
    'skip_empty' => false,
    'trim' => false,
);

// change a parameter
$dialect->setLineEndings("\n");

// create the reader
$reader = new CsvReader($dialect);

//or a writer
$writer = new CsvWriter($dialect);
```

Requirements
------------

[](#requirements)

- PHP &gt;= 5.3.3
- extension mbstring

Suggested :

- extension iconv

Licensing
---------

[](#licensing)

License LGPL 3

- Copyright (C) 2012 Spyrit Systeme

This file is part of LightCSV.

LightCSV is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

LightCSV is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with LightCSV. If not, see .

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~74 days

Total

5

Last Release

4490d ago

Major Versions

0.2 → 1.02014-01-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/258984d9c3286641f19e451a2dcd96ced89cab356c0a9d1a6b76d45adab71c54?d=identicon)[spyrit](/maintainers/spyrit)

---

Top Contributors

[![csanquer](https://avatars.githubusercontent.com/u/372677?v=4)](https://github.com/csanquer "csanquer (40 commits)")[![acornu](https://avatars.githubusercontent.com/u/4006785?v=4)](https://github.com/acornu "acornu (4 commits)")[![Maxooo](https://avatars.githubusercontent.com/u/1563876?v=4)](https://github.com/Maxooo "Maxooo (4 commits)")

---

Tags

parserexportcsvwriterreaderimport

### Embed Badge

![Health badge](/badges/spyrit-light-csv/health.svg)

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

###  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)[csanquer/colibri-csv

Lightweight and performant CSV reader and writer library

16161.7k4](/packages/csanquer-colibri-csv)[goodby/csv

CSV import/export library

9555.6M23](/packages/goodby-csv)[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

582599.4k1](/packages/faisalman-simple-excel-php)[shuchkin/simplecsv

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

5192.4k](/packages/shuchkin-simplecsv)

PHPackages © 2026

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