Download the PHP package alexskrypnyk/csvtable without Composer
On this page you can find all versions of the php package alexskrypnyk/csvtable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexskrypnyk/csvtable
More information about alexskrypnyk/csvtable
Files in alexskrypnyk/csvtable
Package csvtable
Short Description PHP class to parse and format CSV content.
License GPL-3.0-or-later
Homepage https://github.com/AlexSkrypnyk/CsvTable
Informations about the package csvtable
PHP class to parse and format CSV content
[](https://github.com/AlexSkrypnyk/CsvTable/issues)
[](https://github.com/AlexSkrypnyk/CsvTable/pulls)
[](https://github.com/AlexSkrypnyk/CsvTable/actions/workflows/test-php.yml)
[](https://codecov.io/gh/AlexSkrypnyk/CsvTable)



✨ 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.
📋 Requirements
PHP 8.3 or newer. The class uses only the PHP standard library, so CsvTable.php can also be dropped into a project that does not use Composer.
📦 Installation
The class is AlexSkrypnyk\CsvTable\CsvTable.
🚀 Usage
Given a CSV file with the following content:
From string
will produce identical CSV content by default:
From file
will produce identical CSV content by default:
fromFile() throws an Exception when the file is missing or cannot be read.
Reading the parsed data
parse() populates the header and the rows, which are then available through getHeader() and getRows(). Calling format() parses the content automatically, so parse() is only needed when reading the data directly.
Custom separator, enclosure and escape characters
The constructor and fromFile() both accept the separator, enclosure and escape characters used to read the content. They default to ,, " and \.
These characters apply to parsing only. The csv formatter writes using its own separator, enclosure and escape options, so semicolon-separated input is written back as comma-separated content unless the formatter is told otherwise:
Using table formatter
will produce table content:
Using table formatter without a header
will produce table content:
withHeader() restores the default behaviour of treating the first row as a header.
Using markdown_table formatter
will produce Markdown table:
Formatter options
Options are passed as the second argument to format() and are merged over the defaults below.
| Formatter | Option | Default | Description |
|---|---|---|---|
csv |
separator |
, |
Character written between values. |
csv |
enclosure |
" |
Character used to enclose values. |
csv |
escape |
\ |
Character used to escape special characters. |
table |
column_separator |
\| |
String written between columns. |
table |
row_separator |
\n |
String written between rows. |
markdown_table |
column_separator |
\| |
String written between columns. |
markdown_table |
row_separator |
\n |
String written between rows. |
markdown_table |
header_separator |
- |
Character filling the row under the header. |
markdown_table |
value_row_separator |
<br/> |
Replaces newlines found within a value. |
will produce:
Custom formatter as an anonymous callback
A formatter receives the header columns, the rows and the options, and returns the formatted string.
will produce:
Custom formatter as a class with default format method
When a class name is passed, its static format() method is called.
Custom formatter as a class with a custom method and options
format() throws an Exception when the value passed to it cannot be resolved to a callable.
🔀 Column Manipulation
Given a CSV file with the following content:
Reorder columns with columnOrder()
Reorder columns by specifying the desired order. Columns not specified are appended in their original order.
will produce:
Filter to specific columns with onlyColumns()
Keep only the specified columns in the output, in the order specified.
will produce:
Exclude columns with withoutColumns()
Exclude specified columns from the output. The remaining columns keep their original order.
will produce:
Using column indices
All column methods accept both column names (strings) and zero-based indices (integers). An unknown name or an out-of-range index throws an InvalidArgumentException.
Names are resolved against the header, so content parsed with withoutHeader() can only be addressed by index.
Combining column transformations
Column transformations are applied in order: onlyColumns() → withoutColumns() → columnOrder().
will produce:
Reset column transformations
resetColumns() clears all three transformations at once. resetColumnOrder(), resetOnlyColumns() and resetWithoutColumns() clear them individually.
🤝 Contributing
See CONTRIBUTING.md for local development setup and the linting and testing commands.
🔄 Updating
To pull the latest infrastructure from the template into this project, ask Claude Code to "update scaffold" - see AGENTS.md for details.
This repository was created using the Scaffold project template
