maddhatter/markdown-table

动态生成Markdown表格

1.2.0 2023-05-11 13:28 UTC

This package is auto-updated.

Last update: 2024-09-10 13:04:33 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

这是一个用于动态生成Markdown表格的小型包,如此处所述。

安装

使用composer安装

composer require maddhatter/markdown-table

使用方法

// create instance of the table builder
$tableBuilder = new \MaddHatter\MarkdownTable\Builder();

// add some data
$tableBuilder
	->headers(['Tables','Are','Cool']) //headers
	->align(['L','C','R']) // set column alignment
	->rows([ // add multiple rows at once
		['col 1 is', 'left-aligned', '$1600'],
		['col 2 is', 'centered', '$12'],
	])
	->row(['col 3 is', 'right-aligned', '$1']); // add a single row

// display the result
echo $tableBuilder->render();

结果

| Tables   |      Are      |  Cool |
|----------|:-------------:|------:|
| col 1 is | left-aligned  | $1600 |
| col 2 is |   centered    |   $12 |
| col 3 is | right-aligned |    $1 |