All Projects → phplucidframe → console-table

phplucidframe / console-table

Licence: other
ConsoleTable helps you to display tabular data in a terminal/shell/console

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to console-table

core
Platform for rapid application development.
Stars: ✭ 31 (-59.21%)
Mutual labels:  php-framework
sowerphp
Framework PHP hecho en Chile
Stars: ✭ 12 (-84.21%)
Mutual labels:  php-framework
oas
ระบบบัญชีออนไลน์ Online Accounting System (OAS)
Stars: ✭ 51 (-32.89%)
Mutual labels:  php-framework
php-framework-benchmark
php framework benchmark (include laravel、symfony、silex、lumen、slim、yii2、tastphp etc)
Stars: ✭ 17 (-77.63%)
Mutual labels:  php-framework
hello-script
PHP 多进程脚本框架
Stars: ✭ 23 (-69.74%)
Mutual labels:  php-framework
DelphiConsole
The Console class from C# ported to Delphi
Stars: ✭ 101 (+32.89%)
Mutual labels:  console-tool
rawphp
A powerful, robust and API-first, PHP framework that helps people from different PHP backgrounds work on the same project seamlessly. You can write Laravel, CakePHP, Slim, Symphone and Procedural PHP code inside it and it all works perfectly. Its the PHP Framework for everyone.
Stars: ✭ 31 (-59.21%)
Mutual labels:  php-framework
framework
The Bow Framework
Stars: ✭ 33 (-56.58%)
Mutual labels:  php-framework
framework
The Peak Framework
Stars: ✭ 20 (-73.68%)
Mutual labels:  php-framework
betephp
BetePHP - A simple PHP Framework that just work.
Stars: ✭ 77 (+1.32%)
Mutual labels:  php-framework
viewb
convert the command to a web server
Stars: ✭ 12 (-84.21%)
Mutual labels:  console-tool
CryptoManana
An Advanced PHP Cryptography Framework
Stars: ✭ 15 (-80.26%)
Mutual labels:  php-framework
OnceBuilder
OnceBuilder - managment tool, mange projects, templates, plugins in one place.
Stars: ✭ 18 (-76.32%)
Mutual labels:  php-framework
Zest Framework
Core files of AlphaZ Framework
Stars: ✭ 15 (-80.26%)
Mutual labels:  php-framework
broadworks-ocip
PHP Framework for interacting with the Broadworks OCI Provisioning API
Stars: ✭ 26 (-65.79%)
Mutual labels:  php-framework
hleb
PHP Micro-Framework HLEB
Stars: ✭ 58 (-23.68%)
Mutual labels:  php-framework
terminalplot
No description or website provided.
Stars: ✭ 40 (-47.37%)
Mutual labels:  console-tool
OwOFrame
A lightweight MVC framework for PHP
Stars: ✭ 46 (-39.47%)
Mutual labels:  php-framework
coinbash
💰 A bash script (CLI) for displaying crypto currencies market data in a terminal 🖥
Stars: ✭ 110 (+44.74%)
Mutual labels:  console-tool
Lightweight-PHP-Framework-For-Web-and-APIs
Simple PHP framework that helps you quickly understand and write simple APIs.
Stars: ✭ 24 (-68.42%)
Mutual labels:  php-framework

PHP ConsoleTable

ConsoleTabe makes you easy to build console style tables. It helps you to display tabular data in terminal/shell. This is a component of PHPLucidFrame.

License: MIT

Composer Installation

composer require phplucidframe/console-table

Example 1: Bordered Table (Default)

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->addHeader('Language')
    ->addHeader('Year')
    ->addRow()
        ->addColumn('PHP')
        ->addColumn(1994)
    ->addRow()
        ->addColumn('C++')
        ->addColumn(1983)
    ->addRow()
        ->addColumn('C')
        ->addColumn(1970)
    ->display()
;

You can also print the table using getTable method such as echo $table->getTable();

Output:

+----------+------+
| Language | Year |
+----------+------+
| PHP      | 1994 |
| C++      | 1983 |
| C        | 1970 |
+----------+------+

Example 2: Bordered Table with Padding Width 2

You can also use setHeaders() and addRow with Arrays.

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->setPadding(2)
    ->display()
;

Output:

+------------+--------+
|  Language  |  Year  |
+------------+--------+
|  PHP       |  1994  |
|  C++       |  1983  |
|  C         |  1970  |
+------------+--------+

Example 3: Bordered Table with Left Margin Width 4

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->setIndent(4)
    ->display()
;

Output:

    +----------+------+
    | Language | Year |
    +----------+------+
    | PHP      | 1994 |
    | C++      | 1983 |
    | C        | 1970 |
    +----------+------+

Example 4: Non-bordered Table with Header

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->hideBorder()
    ->display()
;

Output:

 Language  Year
----------------
 PHP       1994
 C++       1983
 C         1970

Example 5: Non-bordered Table without Header

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->hideBorder()
    ->display()
;

Output:

 PHP  1994
 C++  1983
 C    1970

Example 6: Table with all borders

require 'src/LucidFrame/Console/ConsoleTable.php';

$table = new LucidFrame\Console\ConsoleTable();
$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addRow(array('C++', 1983))
    ->addRow(array('C', 1970))
    ->showAllBorders()
    ->display()
;

Alternatively, you can use addBorderLine() for each row.

$table
    ->setHeaders(array('Language', 'Year'))
    ->addRow(array('PHP', 1994))
    ->addBorderLine()
    ->addRow(array('C++', 1983))
    ->addBorderLine()
    ->addRow(array('C', 1970))
    ->display()
;

Output

+----------+------+
| Language | Year |
+----------+------+
| PHP      | 1994 |
+----------+------+
| C++      | 1983 |
+----------+------+
| C        | 1970 |
+----------+------+

Test

If you have PHPUnit installed in your machine, you can run test at your project root.

composer install
phpunit tests

If you don't have PHPUnit, you can simply run this in your terminal.

php example.php
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].