<?php class tabloYap { var $border = "1"; var $genislik = "500"; var $class = "tabledefault"; var $tabloveri = Array(); var $satirlar = 0; var $ilksatirlartil = "tablehead"; var $hucredoldur = "2"; var $hucrearalik = "0"; var $kenarrengi = "#666666"; function degerAyarla($anahtar, $deger) { $this->$anahtar = $deger; } function ciktiAl () { $tampon = "\n<TABLE BORDER=\"$this->border\" WIDTH=\"$this->genislik\" BORDERCOLOR=\"$this->kenarrengi\""; $tampon .= " CLASS=\"$this->class\" CELLPADDING=\"$this->hucredoldur\" CELLSPACING=\"$this->hucrearalik\">\n"; for ($i = 1; $i <= $this->satirlar; $i++) { $satirveri = $this->tabloveri[$i]; IF (is_array($satirveri)) { IF ($i == 1 && $this->ilksatirlartil) { $tampon .= " <TR class=\"$this->ilksatirlartil\"> \n"; } ELSE { $tampon .= " <TR>\n"; } while (list($anahtar, $deger) = each($satirveri)) { $tampon .= " <TD"; $tampon .= ($deger["birlesiksatir"]) ? " COLSPAN=\"".$deger["birlesiksatir"]."\"" : ""; $tampon .= ($deger["genislik"]) ? " WIDTH=\"".$deger["genislik"]."\">" : ">"; $tampon .= ($deger["deger"]) ? $deger["deger"] : " "; $tampon .= "</TD>\n"; } $tampon .= " </TR>\n"; } } $tampon .= "</TABLE>\n"; return $tampon; } function satirEkle($stil = false) { $this->satirlar++; } function hucreEkle($deger = false, $birlesiksatir = false, $genislik = false) { $this->tabloveri[$this->satirlar][] = Array ( "deger" => $deger, "birlesiksatir" => $birlesiksatir, "genislik" => $genislik); } } $table = new tabloYap; $table->satirEkle(); $table->hucreEkle("",'',20); $table->hucreEkle("Ozellik",'',20); $table->hucreEkle("Deger"); $table->satirEkle(); $table->hucreEkle("Isim:",'',20); $table->hucreEkle("Mehmet",2); $table->satirEkle(); $table->hucreEkle("Adres:",2); $table->hucreEkle("Turkiye"); $table->degerAyarla("border", 1); echo $table->ciktiAl(); ?>
Çıktısı
<TABLE BORDER="1" WIDTH="500" BORDERCOLOR="#666666" CLASS="tabledefault" CELLPADDING="2" CELLSPACING="0"> <TR class="tablehead"> <TD WIDTH="20"> </TD> <TD WIDTH="20">Ozellik</TD> <TD>Deger</TD> </TR> <TR> <TD WIDTH="20">Isim:</TD> <TD COLSPAN="2">Mehmet</TD> </TR> <TR> <TD COLSPAN="2">Adres:</TD> <TD>Turkiye</TD> </TR> </TABLE>