travail / text-simpletable
travail/text-simpletable
v0.1.3
2019-11-01 06:30 UTC
This package is auto-updated.
Last update: 2024-09-14 19:25:27 UTC
README
名称
Text\SimpleTable - 简单的视觉吸引ASCII表格
概要
use Text\SimpleTable; require_once '/path/to/vendor/autoload.php'; $table = new SimpleTable(10, 20); $table->row('KEY1', 'VALUE1'); $table->row('KEY2', 'VALUE2'); $table->row('KEY3', 'VALUE3'); $table->row('KEY4', 'VALUE4'); $table->row('KEY5', 'VALUE5'); echo $table->draw(); /* .------------+----------------------. | KEY1 | VALUE1 | | KEY2 | VALUE2 | | KEY3 | VALUE3 | | KEY4 | VALUE4 | | KEY5 | VALUE5 | '------------+----------------------' */ $table = new SimpleTable(array(10, 'KEY'), array(20, 'VALUE')); $table->row('KEY1', 'VALUE1'); $table->row('KEY2', 'VALUE2'); $table->row('KEY3', 'VALUE3'); $table->row('KEY4', 'VALUE4'); $table->row('KEY5', 'VALUE5'); echo $table->draw(); /* .------------+----------------------. | KEY | VALUE | +------------+----------------------+ | KEY1 | VALUE1 | | KEY2 | VALUE2 | | KEY3 | VALUE3 | | KEY4 | VALUE4 | | KEY5 | VALUE5 | '------------+----------------------' */ $table = new SimpleTable(10, 20); $table->row('KEY1', 'VALUE1'); $table->hr(); $table->row('KEY2', 'VALUE2'); $table->hr(); $table->row('KEY3', 'VALUE3'); echo $table->draw(); /* .------------+----------------------. | KEY1 | VALUE1 | +------------+----------------------+ | KEY2 | VALUE2 | +------------+----------------------+ | KEY3 | VALUE3 | '------------+----------------------' */ $table = new SimpleTable(array(10, '国'), array(20, '首都')); $table->row('日本', '東京'); $table->row('America', 'Washington D.C.'); $table->row('England', 'London'); $table->row('France', 'Paris'); $table->row('台湾', '台北'); // Set encoding, "UTF-8" by default. // $table->setEncoding($encoding); echo $table->draw(); /* .------------+----------------------. | 国 | 首都 | +------------+----------------------+ | 日本 | 東京 | | America | Washington D.C. | | England | London | | France | Paris | | 台湾 | 台北 | '------------+----------------------' */
安装
要通过composer将此包安装到您的项目中,请将以下代码片段添加到您的composer.json
文件中。然后运行composer install
。
"require": {
"travail/text-simpletable": "dev-master"
}
如果您想从GitHub安装,请添加以下内容
"repositories": [
{
"type": "vcs",
"url": "git@github.com:travail/php-Text-SimpleTable.git"
}
]
方法
__construct
__construct(int $width [, int $width [, ...]])
要绘制简单表格,请将$width设置为列数。
__construct(array ($width, $col_name) [, array ($width, $col_name) [, ...]])
要绘制带有标题的表格,请将$width和$col_name数组设置为列数。
row
void row(string $value [, string $value [, ...]])
绘制行。
hr
void hr(void)
绘制水平线。
setEncoding
void setEncoding(string $encoding)
要绘制多字节字符的表格,请设置当前字符编码。默认为UTF-8。
getEncoding
string getEncoding()
返回当前字符编码。
draw
string draw(void)
绘制文本表格。
感谢
Sebastian Riedel,sri@cpan.org
。
作者
travail
许可证
此库是免费软件。您可以在与PHP相同的条款下重新分发或修改它。