views:

232

answers:

2

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

Basically, 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.

+2  A: 

This is EXACTLY what you are looking for:

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

This may accomplish something similar to what you are looking for:

http://www.paggard.com/projects/txt.generator/

yuval
+2  A: 

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.

jason
Damn, I wonder when Zend Framework's API will become as large as PHP's ;)
Alan Storm