[b]De class (PHP 5)[/b]
<?php

class Table 
{
	const NL = "\r\n"; # newline om de HTML-code overzichtelijk te houden
	
	public function __construct($width = 600, $extra = '') {
		echo self::NL . '<table class="cl_table" cellspacing="0" cellpadding="5" width="' .$width. '" ' .$extra. '>' . self::NL;
	}
	
	public function th() {
		echo '<tr>' . self::NL;
		
		foreach (func_get_args() as $value ) {
			echo '<th class="cl_th">' .$value. '</th>' . self::NL;
		}
		
		echo '</tr>' . self::NL;
	}
	
	public function td() {
		echo '<tr>' . self::NL;
		
		foreach (func_get_args() as $value ) {
			if (!is_array($value) ) {
				echo '<td class="cl_td">' .$value. '</td>' . self::NL;
			}
			else {
				echo '<td class="cl_td" ' .$value[1]. '>' .$value[0]. '</td>' . self::NL;
			}			
		}
		
		echo '</tr>' . self::NL;
	}
	
	public function close() {
		echo '</table>' . self::NL . self::NL;
	}
}

?>

[b]Gebruik van de class[/b]
<?php

$table = new Table; # maak tabel aan 
$table->th('Naam', 'Adres', 'Woonplaats'); # maak kopjes
$table->td('Jan Janssen', 'Kalverstraat 1', 'Amsterdam'); # voeg rij toe
$table->td('Klaas Klaassen', 'Binnenhof 1', 'Den Haag'); # voeg rij toe
$table->td('Piet Pietersen', 'Euromast 1', 'Rotterdam'); # voeg rij toe
$table->close(); # sluit tabel

?>

Of bijvoorbeeld:

<?php

$table = new Table(200); # maak tabel aan van 200px breed
$table->th('Naam'); # maak kopjes
$table->td('Jan Janssen'); # voeg rij toe
$table->td('Klaas Klaassen'); # voeg rij toe
$table->td('Piet Pietersen'); # voeg rij toe
$table->close(); # sluit tabel

?>


[b]Extra attributen[/b]
Als je bij slechts één <td> een toevoeging wilt, dan kan dat door een array te gebruiken, dus bijvoorbeeld:

<?php
$table->td( array('Piet Pietersen', 'bgcolor="#EEEEEE"'), 'Euromast 1', 'Rotterdam'); # voeg rij toe
?>

Een toevoeging aan de <table> kan door een tweede argument mee te geven aan de class zelf.

[b]Usage[/b]
mixed [b]Table[/b] ( [int width] [, string html_attribute] )
mixed [b]th[/b] ( mixed column_name [, mixed ...] ] )
mixed [b]td[/b] ( mixed column_value [, mixed ...]  )
mixed [b]close[/b] ( void )




[b]Class in PHP 4 (werking hetzelfde)[/b]
[i]Thank you Eris[/i]
<?php
define('NL',"\r\n"); # newline om de HTML-code overzichtelijk te houden
class Table 
{
    function Table($width = 600, $extra = ''){
        echo NL . '<table class="cl_table" cellspacing="0" cellpadding="5" width="' .$width. '" ' .$extra. '>' . NL;
    }
     function th() {
        echo '<tr>' . NL;
        
        foreach (func_get_args() as $value ) {
            echo '<th class="cl_th">' .$value. '</th>' . NL;
        }
        
        echo '</tr>' . NL;
    }
    
    function td() {
        echo '<tr>' . NL;
        
        foreach (func_get_args() as $value ) {
            if (!is_array($value) ) {
                echo '<td class="cl_td">' .$value. '</td>' . NL;
            }
            else {
                echo '<td class="cl_td" ' .$value[1]. '>' .$value[0]. '</td>' . NL;
            }            
        }
        
        echo '</tr>' . NL;
    }
    
    function close() {
        echo '</table>' . NL . NL;
    }
}


$table = new Table; # maak tabel aan 
$table->th('Naam', 'Adres', 'Woonplaats'); # maak kopjes
$table->td('Jan Janssen', 'Kalverstraat 1', 'Amsterdam'); # voeg rij toe
$table->td('Klaas Klaassen', 'Binnenhof 1', 'Den Haag'); # voeg rij toe
$table->td('Piet Pietersen', 'Euromast 1', 'Rotterdam'); # voeg rij toe
$table->close(); # sluit tabel

?> 