Skip to content

Air-Petr/php-tabulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP tabulator

Pretty-print the tabular data in various ways.

Instalation

composer require ar-petr/php-tabulator

Usage

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:

Plain

echo Tabulator::getPlain($data, $headers);

/*
id first_name last_name
 1 Lila       Hevner   
 2 Florrie    Gravie   
*/

Simple

echo Tabulator::getSimple($data, $headers);

/*
id first_name last_name
-- ---------- ---------
 1 Lila       Hevner   
 2 Florrie    Gravie   
*/

GitHub

echo Tabulator::getGitHub($data, $headers);

/*
| id | first_name | last_name |
| -- | ---------- | --------- |
|  1 | Lila       | Hevner    |
|  2 | Florrie    | Gravie    |
*/

More types may be added in the future.

Numbers

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 |

Demo

You can see some examples by running scripts from a demo folder:

php demo/plain.php
php demo/github.php
# etc.

Testing

Run tests by:

composer test

About

Text tables in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages