Question

Is there a de-facto standard library for creating ASCII "tables" in PHP?

I want some PHP code that, when handed an array or other data structure will output tables that look something like the mysql command line client's results

+--------+---------------------+----------------------------------+
| fld_id | fld_name            | fld_email                        |
+--------+---------------------+----------------------------------+
|      1 | A value             | another value                    | 
|      2 | A value             |                                  | 
|      3 | A value             | another value                    | 
+--------+---------------------+----------------------------------+

Not rocket science, or even computer science, but certainly tedious science that someone's already solved.

Was it helpful?

Solution

While it's not the defacto standard, the Zend_Text_Table component of the Zend Framework does exactly this.

It has the added bonus of being highly configurable and modular; for example it affords you control over all sorts of formatting details. Also, it adheres to strict OOP principals, if that matters to you.

While the fact that it is part of a larger library may be intimidating, the component is fairly decoupled, the only dependency I can see is on the Zend_Loader_PluginLoader, for its pluggable rendering engine.

Most importantly, it fully supports UTF-8.

OTHER TIPS

This is what you are looking for:

http://code.google.com/p/php-text-table/

Simpler than Zend\Text\Table: https://github.com/viossat/arraytotexttable

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top