Skip to content

maddhatter/markdown-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Markdown Table

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

A small package to dynamically generate Markdown tables, as described here.

Install

Install using composer:

composer require maddhatter/markdown-table

Usage

// 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();

Result

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