Cellbrush table generator

Cellbrush is (yet another) PHP library to generate HTML tables.
It does support colspan and rowspan.

What really makes it special is that table cells are addressed by string keys, and empty cells are filled automatically. This means, you can add cells in any order, and you don't need to babysit the table's structural integrity! This allows for a more semantical work flow.

Features

  • Named rows and columns.
  • Colspan and rowspan using col groups and row groups.
  • Automatically fills up empty cells.
  • Method chaining instead of crazy nested array structures.

Example

Here is the code..

<?php
$table
= (new Table())
 
// A 3x3 grid + 'legend' column on the left.
 
->addColNames(['legend', 'col0', 'col1', 'col2'])
  ->
addRowNames(['row0', 'row1', 'row2'])
  ->
td('row0', 'col0', 'Diag 0')
  ->
td('row1', 'col1', 'Diag 1')
  ->
td('row2', 'col2', 'Diag 2')
 
// Add a separator column on the right.
 
->addColName('separator')
  ->
td('', 'separator', '//')
 
// Add colspan group on the right.
 
->addColGroup('cg', ['a', 'b', 'c'])
  ->
td('row0', 'cg.a', 'GD 0.a')
  ->
td('row0', 'cg.b', 'GD 0.b')
  ->
td('row1', 'cg', 'Span')
  ->
td('row2', 'cg.a', 'GD 3.a')
  ->
td('row2', 'cg.c', 'GD 3.c')
;
// Add a thead section.
$table->thead()->addRow('head0')
  ->
th('col0', 'Column 0')
  ->
th('col1', 'Column 1')
  ->
th('col2', 'Column 2')
  ->
th('cg', 'Grouped columns')
;
// Fill the legend cells.
$table->colHandle('legend')
  ->
th('row0', 'Row 0')
  ->
th('row1', 'Row 1')
  ->
th('row2', 'Row 2')
;
print
$table->render();
?>

And this is the generated table:

Column 0Column 1Column 2Grouped columns
Row 0Diag 0//GD 0.aGD 0.b
Row 1Diag 1Span
Row 2Diag 2GD 3.aGD 3.c