Zend Certified Engineer

phpguru.org

Free PHP, Javascript and C# code

Console_Table class

This class provides an API to easily generate tables for Console applications (like the tables generated by the MySQL client application in SELECT queries). Eg:

+----------+----------+------------+----------+
| Header 1 | Header 2 | Header 3   | Header 4 |
+----------+----------+------------+----------+
| 1        | 2        | 10/08/2002 | 1        |
| one      | two      | 11/08/2002 | 2        |
| foo      | bar      | 12/08/2002 | 3        |
+----------+----------+------------+----------+

The code used to generate the above table is:


<?php
include_once('Console/Table.php');

$table = &new Console_Table();

$table->addRow(array(1, 2, 3));
$table->addRow(array('one', 'two', 'three'));

$table->insertRow(array('foo', 'bar'), 2);

$table->addCol(array('1', '2', '3'), 3);
$table->addCol(array('10/08/2002', '11/08/2002', '12/08/2002'), 2);

$table->setHeaders(array('Header 1', 'Header 2', 'Header 3', 'Header 4'));

echo
$table->getTable();
?>

This class is available here.

Link to me

If you use any of the code on this site (and if you don't I guess) or it makes your life easier, I'd appreciate a link - http://www.phpguru.org. Thanks!

Last modified: 14:32 16th February 2008