Download .zip |
Info | Example | View files (9) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2019-12-16 (5 hours ago) | Not enough user ratings | Total: 161 | All time: 8,643 This week: 327 |
Version | License | PHP version | Categories | |||
console-table 1.0.2 | MIT/X Consortium ... | 5 | PHP 5, Text processing, Console |
Description | Author | |||||||||||||
This class can display data in a table of console text characters. |
|
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 require phplucidframe/console-table
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 |
+----------+------+
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 |
+------------+--------+
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 |
+----------+------+
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
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
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 |
+----------+------+
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
Files |
File | Role | Description | ||
---|---|---|---|---|
src (1 directory) | ||||
tests (1 directory) | ||||
bootstrap.php | Example | Example script | ||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
example.php | Example | Example usage | ||
LICENSE | Lic. | License | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | README |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.