問題描述
是否有用于在 PHP 中創建 ASCII表"的事實上的標準庫?
Is there a de-facto standard library for creating ASCII "tables" in PHP?
我想要一些 PHP 代碼,當處理數組或其他數據結構時,它會輸出類似于 mysql 命令行客戶端結果的表
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.
推薦答案
雖然它不是事實上的標準,Zend_Text_Table
組件正是這樣做的.
While it's not the defacto standard, the Zend_Text_Table
component of the Zend Framework does exactly this.
它具有高度可配置和模塊化的額外好處;例如,它使您可以控制各種格式細節.此外,它遵守嚴格的 OOP 原則(如果這對您很重要).
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.
雖然它是更大庫的一部分這一事實可能令人生畏,但該組件是相當解耦的,我能看到的唯一依賴項是 Zend_Loader_PluginLoader
,因為它的可插拔渲染引擎.
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.
最重要的是,它完全支持 UTF-8.
Most importantly, it fully supports UTF-8.
這篇關于PHP ASCII 表庫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!