<?php class Tablo{ var $topla; var $say; function Tablo(){ $ar["border"]="border=0"; $ar["cellspacing"]="cellspacing=0"; $ar["cellpadding"]="cellpadding=0"; $this->args(func_get_args(),$ar); $this->topla="<table ".implode(" ",$ar).">"; $this->say = 0; } function tr(){ if($this->say++) $this->topla.="</tr>"; $this->args(func_get_args(),$ar); $this->topla.="<tr ".implode(" ",$ar).">"; } function td(){ $args=func_get_args(); $veri=array_shift($args); $this->args($args,$ar); $this->topla.="<td ".implode(" ",$ar).">$veri</td>"; } function th(){ $args=func_get_args(); $veri=array_shift($args); $this->args($args,$ar); $this->topla.="<th ".implode(" ",$ar).">$veri</th>"; } function rows(){ return $this->say; } function html(){ if($this->say) $this->topla.="</tr>"; $this->say = 0; return $this->topla."</table>"; } function args($args,&$ar){ settype($ar,"array"); foreach ($args as $v){ if (is_array($v)){ foreach ($v as $ii=>$vv){ if(is_string($ii)){ $n = strtolower($ii); if($vv && is_string($vv) && $vv[0]!="'" && $vv[0]!='"') $vv = '"'.$vv.'"'; $ar[$n] = strlen($vv) ? "$ii=$vv" : $ii; }else{ $n = explode("=",$vv); $n = strtolower($n[0]); $ar[$n] = $vv; } } }else{ $n=explode("=",$v); $n=strtolower($n[0]); if ($v) $ar[$n]=$v; } } return $ar; } } $tbl=new Tablo("border=1"); $tbl->tr(); $tbl->td("Merhaba","bgcolor=#ffffff","style='color:#000000'"); $tbl->tr(); $tbl->td("Yazılımcı"); print($tbl->html()); ?>
Çıktısı
<table border=1 cellspacing=0 cellpadding=0> <tr > <td bgcolor=#ffffff style='color:#000000'> Merhaba </td> </tr> <tr > <td > Yazılımcı </td> </tr> </table>