protected function table($element)
{
$rows = array();
foreach ($element->childNodes as $node) {
if ($node instanceof DOMText || $node->tagName === 'tfoot') {
continue;
}
if ($node->tagName === 'thead' || $node->tagName === 'tbody') {
$rows = $rows + $this->table_section($node);
} elseif ($node->tagName === 'tr') {
$rows[] = $this->table_row($node);
}
}
$cols[] = array();
foreach ($rows as $row => $cells) {
foreach ($cells as $col => $content) {
$cols[$col][$row] = $content;
}
}
$rows = array();
foreach ($cols as $col => $cells) {
$length = max(array_map('strlen', $cells));
var_dump($length);
foreach ($cells as $row => $content) {
$rows[$row][$col] = str_pad($content, $length);
}
}
$text = '';
$row_length = 0;
foreach ($rows as $num => $row) {
$text .= '|';
foreach ($row as $cell) {
$text .= ' ' . $cell . ' |';
}
if ($num === 0) {
$row_length = strlen($text) - 2;
$text = '+' . str_repeat('-', $row_length) . "+\n" . $text . "\n" . '+' . str_repeat('-', $row_length) . '+';
}
$text .= "\n";
}
$text .= '+' . str_repeat('-', $row_length) . "+\n";
#var_dump($text);
return $text;
}