I love this little class. It probably doesn't seem a big thing at first, but once you build a table using this class you will never look back. I wrote this class because I was tired of counting rows and cells and trying to keep a mental image of everything that was going on. I wanted to be able to see in an instant where my rows were, and what was going on in each cell. When you get involved with nested tables the beauty of this class becomes even more apparent. This class will make your tables:

  • Readable
  • Easy to edit
  • Simple to create
  • Have reliable, and valid markup

Creates a new table object

$vars A '|' delimited string of table attributes and their values. No quotes needed.
Example
$tb = new Table('class=center');

This method starts a new row in your table.

$align This var will align ('left', 'center', or 'right') your content within every cell across the board. If you want to center every cell in the row then it's easier to say so once here, then to add 'align=center' to every cell in the row hereafter.
$bgcolor To color your row a different color you can enter that value here. ('#A5A5A5' or 'gray', etc.)
Returns A string of code to add to your $html.
Example
$html .= $tb->row('center');

This method opens a new cell, but does not close ('</td>') it. That happens when you open another cell, create a new row, or close out the form.

$vars A '|' delimited string of cell attributes and their values. No quotes needed.
$content What you want to display inside your cell. This is optional because everything you add to your $html after this will go inside this cell.
Returns A string of code to add to your $html.
Example
$html .= $tb->cell('colspan=2|valign=bottom', 'I span two cells.'); 
$html .= $tb->cell(); 
$html .= 'I am a normal cell, and this text will still be contained within it.';

This will close out your table and everything else that is open.

Returns A string of code to add to your $html.
Example
$html .= $tb->close();
Download