air-petr / php-tabulator
PHP中的表格数据
v1.0.2
2022-02-10 19:09 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-11 00:45:48 UTC
README
以各种方式美化打印表格数据。
安装
composer require ar-petr/php-tabulator
使用方法
您将获得一个具有静态接口的Tabulator
类
use AirPetr\Tabulator; $body = [ [1, 'Lila', 'Hevner'], [2, 'Florrie', 'Gravie'], ]; $header = ['id', 'first_name', 'last_name']; echo Tabulator::getPlain($body); // Table without headers echo Tabulator::getPlain($body, $header); // Table with headers
输出类型不同
纯文本
echo Tabulator::getPlain($data, $headers); /* id first_name last_name 1 Lila Hevner 2 Florrie Gravie */
简单
echo Tabulator::getSimple($data, $headers); /* id first_name last_name -- ---------- --------- 1 Lila Hevner 2 Florrie Gravie */
GitHub
echo Tabulator::getGitHub($data, $headers); /* | id | first_name | last_name | | -- | ---------- | --------- | | 1 | Lila | Hevner | | 2 | Florrie | Gravie | */
未来可能会添加更多类型。
数字
带有数字的列左对齐。
| ip_address | age | account |
| --------------- | ---- | -------- |
| 219.249.38.228 | 2362 | 12276.68 |
| 197.81.54.113 | 41 | 6496.03 |
| 176.111.139.6 | 64 | 3291.72 |
| 208.178.177.206 | 34 | 4311.57 |
演示
您可以通过运行来自demo
文件夹的脚本来查看一些示例
php demo/plain.php
php demo/github.php
# etc.
测试
通过以下命令运行测试
composer test