imtiazmahbub / array-to-text-php
这个PHP类可以将数组转换为ascii文本格式的表格
v1.0.2
2018-08-16 09:31 UTC
Requires
- php: ^5.3.3 || ^7.0
This package is not auto-updated.
Last update: 2024-09-29 05:09:14 UTC
README
从 https://gist.github.com/tony-landis/31477 分支
这个PHP类可以将数组转换为ascii文本表格。
示例用法
require_once ('ArrayToTextTable.php');
$data = array(
array('company'=>'AIG', 'id'=>1, 'balance'=> '-$99,999,999,999.00'),
array('company'=>'Wachovia', 'id'=>2, 'balance'=> '-$10,000,000.00'),
array('company'=>'HP', 'id'=>3, 'balance'=> '$555,000.000.00'),
array('company'=>'IBM', 'id'=>4, 'balance'=> '$12,000.00')
);
$renderer = new ArrayToTextTable($data);
$renderer->showHeaders(true);
$renderer->render();
上述示例的输出
+----------+----+---------------------+
| COMPANY | ID | BALANCE |
+----------+----+---------------------+
| AIG | 1 | -$99,999,999,999.00 |
| Wachovia | 2 | -$10,000,000.00 |
| HP | 3 | $555,000.000.00 |
| IBM | 4 | $12,000.00 |
+----------+----+---------------------+
有用方法
render 默认: false
你可以使用 render(true) 捕获渲染的输出
$output = $renderer->render(true);
showHeaders 默认: false
使用数组的键值作为标题显示表头
$renderer->showHeaders(true);
setMaxWidth 默认: 30
设置每列的最大宽度(字符数),超出部分将被截断
$renderer->setMaxWidth(30);
setMaxHeight 默认: 2
设置每行的最大高度(行数),超出部分将被截断
$renderer->setMaxHeight(30);