addHeader($content); * $table->addCaption($caption); * $table->addFooter($content); * $table->addBody($content); * $table->drawTable(); * * Where, * $caption - string Caption for table * $content - array Content for table * array[row][column][attributes] * array[row][attributes] * array[row][column][content] = string * $attributes = array ('attributeName' => 'attributeValue') * @version 1.0 - 2009-05-05 */ class HtmlTable { var $table = ''; var $caption = ''; var $header = array(); var $headerRows = 0; var $headerColumns = 0; var $body = array(); var $bodyRows = 0; var $bodyColumns = 0; var $footer = array(); var $footerRows = 0; var $footerColumns = 0; var $maxColumns = 0; /* On construct we set up the table attributes * for example: class, id, styles, etc */ function __construct($attributes = null) { if (!is_array($attributes) && !is_null($attributes)) { throw new Exception ('Table attributes needs to be an array'); } else { $this->table = $attributes; } } function addHeader($content = null) { if (is_array($content)) { $this->header = $content; } else { throw new Exception ('Header content needs to be an array'); } ksort($this->header); // Find the number of rows and columns in the header $rowColumns = $this->findRowsColumns($this->header); $this->headerRows = $rowColumns[0]; $this->headerColumns = $rowColumns[1]; } function addFooter($content = null) { if (is_array($content)) { $this->footer = $content; } else { throw new Exception ('Footer content needs to be an array'); } ksort($this->footer); // Find the number of rows and columns in the footer $rowColumns = $this->findRowsColumns($this->footer); $this->footerRows = $rowColumns[0]; $this->footerColumns = $rowColumns[1]; } function addBody($content = null) { if (is_array($content)) { $this->body = $content; } else { throw new Exception ('Body content needs to be an array'); } ksort($this->body); // Find the number of rows and columns in the body $rowColumns = $this->findRowsColumns($this->body); $this->bodyRows = $rowColumns[0]; $this->bodyColumns = $rowColumns[1]; } function addCaption($caption = null) { $this->caption = strip_tags($caption); } /* This function generates the HTML for the * table, returninging the HTML as a string. */ function drawTable() { // What was the largest number of columns? $maxColumns = array($this->headerColumns, $this->bodyColumns, $this->footerColumns); $this->maxColumns = max($maxColumns); // Draw the main table 'holder'... $table = '