mmarica/display-table

以文本格式显示表格

1.0.0 2017-01-22 20:44 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:53:17 UTC


README

+=========+========+=======+=========+
| Console | Tables | Made  |  Easy   |
+=========+========+=======+=========+

显示表格

Latest Stable Version Software License Build Status codecov.io

这是一个简单的PHP库,用于生成文本格式的表格,非常适合在日志或控制台编写摘要。

目录

安装

最简单的安装方式是通过composer

$ composer require mmarica/display-table

需求

以下版本的PHP受到支持

  • PHP 5.6
  • PHP 7.0
  • PHP 7.1

文档

示例

打印文本表格就像这样简单

<?php
require_once dirname(__FILE__) . '/vendor/autoload.php';

use Mmarica\DisplayTable;

print DisplayTable::create()
    ->headerRow(['#', 'Person', 'Hobbies'])
    ->dataRows([
        ['1', 'Mihai', 'Cycling, Gaming, Programming'],
        ['2', 'Chewbacca', 'Growling, hibernating'],
        ['3', 'Philip J. Fry', 'Time traveling, eating anchovies'],
    ])
    ->toText()->generate();
.---.---------------.----------------------------------.
| # |    Person     |             Hobbies              |
:---+---------------+----------------------------------:
| 1 | Mihai         | Cycling, Gaming, Programming     |
| 2 | Chewbacca     | Growling, hibernating            |
| 3 | Philip J. Fry | Time traveling, eating anchovies |
'---'---------------'----------------------------------'