Código PHP:
<?php
class GnTabla {
function __construct($class) {
$new_class = ($class != '') ? " class=\"$class\"" : '';
echo "<table$new_class>\n";
}
function Head($cont) {
echo " <thead>\n <tr>\n";
foreach ($cont as $tmp) {
echo " <th>$tmp</th>\n";
}
echo " </tr>\n </thead>\n";
}
function caption($caption) {
echo " <caption>$caption</caption>\n";
}
function Col($col) { //formato de variable array( propiedad => array( valores))
foreach($col as $clave => $valor) {
$n = 0;
foreach($valor as $tmp) {
$fila_col[$n++] .= " $clave=\"$tmp\"";
}
}
for($i = 0; $i<count($fila_col); $i++) {
echo " <col$fila_col[$i]>\n";
}
}
function Body($cont, $class, $style) {
$newclass = ($class!='') ? " class=\"$class\"" : '';
$newstyle = ($style!='') ? " style=\"$style\"" : '';
echo " <tr$newclass$newstyle>\n";
foreach($cont as $tmp) {
echo " <td>$tmp</td>\n";
}
echo " </tr>\n";
}
function FinTabla() {
echo "</table>\n";
}
}
?>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
<head>
</head>
<body>
<?php
$valores = array('primera columna', 'segunda columna', 'tercera columna', 'cuarta columna');
$p = @new GnTabla();
$p->caption('sangre morena');
$p->Head(array('pelo', 'corra', 'cachucha', 'pelo'));
$p->Col(array(
'align' => array( 'left','right', 'center'),
'style' => array('','','')));
$filas = array( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30);
while($datos = each($filas)) {
@$p->Body(array(
$valores[0],
$valores[1],
$valores[2],
$valores[3]));
}
$p->FinTabla();
?>
</body>
</html>