dan-da / texttable-php
此包的最新版本(v1.0.4)没有提供许可证信息。
v1.0.4
2019-10-21 21:18 UTC
Requires
- dan-da/strictmode-php: ^1.0
This package is auto-updated.
Last update: 2024-09-10 11:30:55 UTC
README
这是一个方便的PHP类,用于打印固定宽度的文本表格。
还有一个类用于打印人类友好的Markdown表格。
让我们看几个例子,好吗?
示例价格历史报告(来自 bitprices )
+------------+------------------+-----------+-------------+----------------+---------------+----------+
| Date | BTC Amount | USD Price | USD Amount | USD Amount Now | USD Gain | Type |
+------------+------------------+-----------+-------------+----------------+---------------+----------+
| 2011-11-16 | 500000.00000000 | 2.46 | 1230000.00 | 189905000.00 | 188675000.00 | purchase |
| 2011-11-16 | -500000.00000000 | 2.46 | -1230000.00 | -189905000.00 | -188675000.00 | sale |
| 2013-11-26 | 0.00011000 | 913.95 | 0.10 | 0.04 | -0.06 | purchase |
| 2013-11-26 | -0.00011000 | 913.95 | -0.10 | -0.04 | 0.06 | sale |
| 2014-11-21 | 0.00010000 | 351.95 | 0.04 | 0.04 | 0.00 | purchase |
| 2014-12-09 | 0.00889387 | 353.67 | 3.15 | 3.38 | 0.23 | purchase |
| 2015-06-05 | 0.44520000 | 226.01 | 100.62 | 169.09 | 68.47 | purchase |
| 2015-06-07 | 0.44917576 | 226.02 | 101.52 | 170.60 | 69.08 | purchase |
| 2015-10-17 | 0.00010000 | 270.17 | 0.03 | 0.04 | 0.01 | purchase |
| 2015-11-05 | 0.00010000 | 400.78 | 0.04 | 0.04 | 0.00 | purchase |
| Totals: | 0.90356963 | | 205.40 | 343.19 | 137.79 | |
+------------+------------------+-----------+-------------+----------------+---------------+----------+
一周中的日子。来自 ./example-weekdays2.php
+-----------+--------+---------+----------+
| Day | Abbrev | Initial | Position |
+-----------+--------+---------+----------+
| Sunday | Sun | S | 0 |
| Monday | Mon | M | 1 |
| Tuesday | Tue | T | 2 |
| Wednesday | Wed | W | 3 |
| Thursday | Thu | T | 4 |
| Friday | Fri | F | 5 |
| Saturday | Sat | S | 6 |
+-----------+--------+---------+----------+
用法。
您可以使用composer进行安装。
$ cd yourproject
$ composer require dan-da/texttable-php
通过以下方式将它们包含到您的代码中:
require_once 'path/to/vendor/autoload.php';
或者直接将它们放入您的项目中。
没有依赖关系!
只需从任何PHP文件中包含texttable.class.php并使用它即可!
这里有一个简单的例子,它会打印关于一周中日子的一些信息。
<?php
require_once( __DIR__ . '/texttable.class.php' );
$data = [];
$timestamp = strtotime('next Sunday');
$days = array();
for ($i = 0; $i < 7; $i++) {
$data[] = ['Day' => strftime('%A', $timestamp),
'Abbrev' => strftime('%a', $timestamp),
'Initial' => strftime('%A', $timestamp)[0],
'Position' => $i ];
$timestamp = strtotime('+1 day', $timestamp);
}
echo " [ Table with header from first row keys. similar to db result set. ]\n";
echo texttable::table( $data );