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.
While it’s not the defacto standard, the
Zend_Text_Tablecomponent 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.