Pretty-print the tabular data in various ways.
composer require ar-petr/php-tabulator
You will get a Tabulator
class with a static interface:
use AirPetr\Tabulator;
$body = [
[1, 'Lila', 'Hevner'],
[2, 'Florrie', 'Gravie'],
];
$header = ['id', 'first_name', 'last_name'];
echo Tabulator::getPlain($body); // Table without headers
echo Tabulator::getPlain($body, $header); // Table with headers
There are different types of output:
echo Tabulator::getPlain($data, $headers);
/*
id first_name last_name
1 Lila Hevner
2 Florrie Gravie
*/
echo Tabulator::getSimple($data, $headers);
/*
id first_name last_name
-- ---------- ---------
1 Lila Hevner
2 Florrie Gravie
*/
echo Tabulator::getGitHub($data, $headers);
/*
| id | first_name | last_name |
| -- | ---------- | --------- |
| 1 | Lila | Hevner |
| 2 | Florrie | Gravie |
*/
More types may be added in the future.
Columns with numbers are flushed to the left.
| ip_address | age | account |
| --------------- | ---- | -------- |
| 219.249.38.228 | 2362 | 12276.68 |
| 197.81.54.113 | 41 | 6496.03 |
| 176.111.139.6 | 64 | 3291.72 |
| 208.178.177.206 | 34 | 4311.57 |
You can see some examples by running scripts from a demo
folder:
php demo/plain.php
php demo/github.php
# etc.
Run tests by:
composer test