PHPackages                             alexskrypnyk/csvtable - 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. alexskrypnyk/csvtable

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

alexskrypnyk/csvtable
=====================

PHP class to parse and format CSV content.

1.2.0(5mo ago)321.8k↓16.9%1[1 issues](https://github.com/AlexSkrypnyk/CsvTable/issues)3GPL-2.0-or-laterPHPPHP &gt;=8.2CI passing

Since May 20Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/AlexSkrypnyk/CsvTable)[ Packagist](https://packagist.org/packages/alexskrypnyk/csvtable)[ Docs](https://github.com/AlexSkrypnyk/CsvTable)[ Patreon](https://www.patreon.com/AlexSkrypnyk)[ RSS](/packages/alexskrypnyk-csvtable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (10)Used By (3)

  ![Yourproject logo](https://camo.githubusercontent.com/d21edcaad80d03bd8bdc3594fc3be5dad6b4a0979c7c6190aa2fc2fe1512c393/68747470733a2f2f706c616365686f6c642e6a702f3030303030302f6666666666662f323030783230302e706e673f746578743d4373765461626c65266373733d253742253232626f726465722d7261646975732532322533412532322532303130307078253232253744)

PHP class to parse and format CSV content
=========================================

[](#php-class-to-parse-and-format-csv-content)

[![GitHub Issues](https://camo.githubusercontent.com/7652cd06c4eb707711ad5c53a9d7ece597ccb3d13485c46380503e628cbb4969/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f416c6578536b7279706e796b2f4373765461626c652e737667)](https://github.com/AlexSkrypnyk/CsvTable/issues)[![GitHub Pull Requests](https://camo.githubusercontent.com/b6ec883be13bc7db61f5b8d19deeed57414d05f97fb8df924e6e77d6e31648ae/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f416c6578536b7279706e796b2f4373765461626c652e737667)](https://github.com/AlexSkrypnyk/CsvTable/pulls)[![Test](https://github.com/AlexSkrypnyk/CsvTable/actions/workflows/test-php.yml/badge.svg)](https://github.com/AlexSkrypnyk/CsvTable/actions/workflows/test-php.yml)[![codecov](https://camo.githubusercontent.com/427aba36e2cd2513f822b7b1c10fa8f9ff1ffbedc9c6b0cf9ac088358632e5a6/68747470733a2f2f636f6465636f762e696f2f67682f416c6578536b7279706e796b2f4373765461626c652f67726170682f62616467652e7376673f746f6b656e3d37574542314958425954)](https://codecov.io/gh/AlexSkrypnyk/CsvTable)[![GitHub release (latest by date)](https://camo.githubusercontent.com/b3e665494ffb1d602f2e52f92b03279e26fd8df1da953a2afa73a99c8b12e9a3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f416c6578536b7279706e796b2f4373765461626c65)](https://camo.githubusercontent.com/b3e665494ffb1d602f2e52f92b03279e26fd8df1da953a2afa73a99c8b12e9a3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f416c6578536b7279706e796b2f4373765461626c65)[![LICENSE](https://camo.githubusercontent.com/5c12f9871a66d92ca9a04b57143121650a487c45358dd601b7292df8b3766367/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f416c6578536b7279706e796b2f4373765461626c65)](https://camo.githubusercontent.com/5c12f9871a66d92ca9a04b57143121650a487c45358dd601b7292df8b3766367/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f416c6578536b7279706e796b2f4373765461626c65)[![Renovate](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)

---

Features
--------

[](#features)

- Single-file class to manipulate CSV table.
- Formatters for CSV, text table and Markdown table.
- Support for a custom formatter.
- Column manipulation: reorder, filter, and exclude columns.

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

[](#installation)

```
composer require alexskrypnyk/csvtable
```

Usage
-----

[](#usage)

Given a CSV file with the following content:

```
col11,col12,col13
col21,col22,col23
col31,col32,col33
```

### From string

[](#from-string)

```
$csv = file_get_contents($csv_file);
// Format using the default formatter.
print (new CsvTable($csv))->format();
```

will produce identical CSV content by default:

```
col11,col12,col13
col21,col22,col23
col31,col32,col33
```

### From file

[](#from-file)

```
print (CsvTable::fromFile($file))->format();
```

will produce identical CSV content by default:

```
col11,col12,col13
col21,col22,col23
col31,col32,col33
```

### Using `text_table` formatter

[](#using-text_table-formatter)

```
print (CsvTable::fromFile($file))->format('text_table');
```

will produce table content:

```
col11|col12|col13
-----------------
col21|col22|col23
col31|col32|col33
```

### Using `text_table` formatter without a header

[](#using-text_table-formatter-without-a-header)

```
print (CsvTable::fromFile($file))->withoutHeader()->format('text_table');
```

will produce table content:

```
col11|col12|col13
col21|col22|col23
col31|col32|col33
```

### Using `markdown_table` formatter

[](#using-markdown_table-formatter)

```
print (CsvTable::fromFile($file))->format('markdown_table');
```

will produce Markdown table:

```
| col11 | col12 | col13 |
|-------|-------|-------|
| col21 | col22 | col23 |
| col31 | col32 | col33 |
```

### Custom formatter as an anonymous callback

[](#custom-formatter-as-an-anonymous-callback)

```
print (CsvTable::fromFile($file))->format(function ($header, $rows, $options) {
  $output = '';

  if (count($header) > 0) {
    $output = implode('|', $header);
    $output .= "\n" . str_repeat('=', strlen($output)) . "\n";
  }

  return $output . implode("\n", array_map(static function ($row): string {
    return implode('|', $row);
  }, $rows));
});
```

will produce CSV content:

```
col11|col12|col13
=================
col21|col22|col23
col31|col32|col33
```

### Custom formatter as a class with default `format` method

[](#custom-formatter-as-a-class-with-default-format-method)

```
print (CsvTable::fromFile($file))->withoutHeader()->format(CustomFormatter::class);
```

### Custom formatter as a class with a custom method and options

[](#custom-formatter-as-a-class-with-a-custom-method-and-options)

```
$formatter_options = ['option1' => 'value1', 'option2' => 'value2'];
print (CsvTable::fromFile($file))->withoutHeader()->format([CustomFormatter::class, 'customFormat'], $formatter_options);
```

Column Manipulation
-------------------

[](#column-manipulation)

Given a CSV file with the following content:

```
Name,Age,City,Country
John,30,New York,USA
Jane,25,London,UK
```

### Reorder columns with `columnOrder()`

[](#reorder-columns-with-columnorder)

Reorder columns by specifying the desired order. Columns not specified are appended in their original order.

```
print (CsvTable::fromFile($file))->columnOrder(['City', 'Name'])->format('markdown_table');
```

will produce:

```
| City     | Name | Age | Country |
|----------|------|-----|---------|
| New York | John | 30  | USA     |
| London   | Jane | 25  | UK      |
```

### Filter to specific columns with `onlyColumns()`

[](#filter-to-specific-columns-with-onlycolumns)

Keep only the specified columns in the output.

```
print (CsvTable::fromFile($file))->onlyColumns(['Name', 'City'])->format('markdown_table');
```

will produce:

```
| Name | City     |
|------|----------|
| John | New York |
| Jane | London   |
```

### Exclude columns with `withoutColumns()`

[](#exclude-columns-with-withoutcolumns)

Exclude specified columns from the output.

```
print (CsvTable::fromFile($file))->withoutColumns(['Age', 'Country'])->format('markdown_table');
```

will produce:

```
| Name | City     |
|------|----------|
| John | New York |
| Jane | London   |
```

### Using column indices

[](#using-column-indices)

All column methods accept both column names (strings) and zero-based indices (integers).

```
// Using indices
print (CsvTable::fromFile($file))->columnOrder([2, 0])->format();

// Using mixed names and indices
print (CsvTable::fromFile($file))->onlyColumns(['Name', 2])->format();
```

### Combining column transformations

[](#combining-column-transformations)

Column transformations are applied in order: `onlyColumns()` → `withoutColumns()` → `columnOrder()`.

```
print (CsvTable::fromFile($file))
  ->withoutColumns(['Age'])
  ->columnOrder(['Country', 'City'])
  ->format('markdown_table');
```

will produce:

```
| Country | City     | Name |
|---------|----------|------|
| USA     | New York | John |
| UK      | London   | Jane |
```

### Reset column transformations

[](#reset-column-transformations)

```
$table = CsvTable::fromFile($file);

// Apply and use transformations
$table->columnOrder(['City', 'Name']);
print $table->format();

// Reset and format without transformations
print $table->resetColumns()->format();

// Individual reset methods are also available:
// $table->resetColumnOrder();
// $table->resetOnlyColumns();
// $table->resetWithoutColumns();
```

Maintenance
-----------

[](#maintenance)

```
composer install
composer lint
composer test
```

---

*This repository was created using the [Scaffold](https://getscaffold.dev/) project template*

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance75

Regular maintenance activity

Popularity32

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~179 days

Total

6

Last Release

166d ago

Major Versions

0.3.0 → 1.0.02024-11-17

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

1.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b57b0fd0b96f77f2efa1a1889af0ae607fa139bcc1256e809ee3ebbb30907364?d=identicon)[alexdrevops](/maintainers/alexdrevops)

---

Top Contributors

[![AlexSkrypnyk](https://avatars.githubusercontent.com/u/378794?v=4)](https://github.com/AlexSkrypnyk "AlexSkrypnyk (26 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (24 commits)")[![tannguyen04](https://avatars.githubusercontent.com/u/2858879?v=4)](https://github.com/tannguyen04 "tannguyen04 (3 commits)")

---

Tags

convertercsvformattermarkdowntable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alexskrypnyk-csvtable/health.svg)

```
[![Health](https://phpackages.com/badges/alexskrypnyk-csvtable/health.svg)](https://phpackages.com/packages/alexskrypnyk-csvtable)
```

###  Alternatives

[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

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

1.2k57.6M131](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)[setasign/tfpdf

This class is a modified version of FPDF that adds UTF-8 support. The latest version is based on FPDF 1.85.

426.1M30](/packages/setasign-tfpdf)[aspera/xlsx-reader

Spreadsheet reader library for XLSX files

52742.2k5](/packages/aspera-xlsx-reader)

PHPackages © 2026

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