Example #1
0
function wtk_txt_center($text, $width, $pad = false)
{
    $lines = explode("\n", $text);
    foreach ($lines as $i => $line) {
        $il = intval(($width - mb_strlen($line)) / 2);
        if ($il) {
            $indent = implode('', array_fill(0, $il, ' '));
        } else {
            $indent = '';
        }
        $lines[$i] = $indent . $line;
        if ($pad) {
            $lines[$i] = wtk_txt_pad($lines[$i], $width);
        }
    }
    return implode("\n", $lines);
}
Example #2
0
ob_start();
if ($show_header) {
    $cells = array();
    $j = 0;
    foreach ($columns as $col) {
        $cells[] = wtk_txt_center($col->getTitle(), $largeurs[$j], true);
        $j++;
    }
    echo $_indent . implode(' | ', $cells) . "\n";
    echo $_indent . wtk_txt_pad('', array_sum($largeurs) + 3 * (count($largeurs) - 1), '—') . "\n";
}
for ($i = 0; $i < $rows; $i++) {
    $cells = array();
    for ($j = 0; $j < $cols; $j++) {
        $id = 'cell-' . $i . '-' . $j;
        wtk_txt_data($this->{$id}, '', $largeurs[$j]);
        $td = $this->{$id}->render();
        $cells[] = explode("\n", $td);
    }
    for ($k = 0; $k < $hauteurs[$i]; $k++) {
        $cs = array();
        for ($j = 0; $j < $cols; $j++) {
            $td = isset($cells[$j][$k]) ? $cells[$j][$k] : "";
            $cs[] = wtk_txt_pad($td, $largeurs[$j]);
        }
        echo $_indent . implode(' | ', $cs) . "\n";
    }
}
$table = ob_get_contents();
ob_end_clean();
echo wtk_txt_center($table, $_width);