将php数组输出为html表格的类,一般用不到... php ?phpclass xtable{private $tit,$arr,$fons,$sextra;public function __construct(){$this-tit=array();// strings with titles for first row $this-arr=array();// data to show on cells$this-fons=array(
将php数组输出为html表格的类,一般用不到... php tit=array(); // strings with titles for first row $this->arr=array(); // data to show on cells $this->fons=array(#eeeeee,#cceeee); // background colors for odd and even rows $this->sextra=; // extra html code for table tag } public function extra($s) // add some html code for the tag table { $this->sextra=$s; } public function background($arr) {if (is_array($arr)) $this->fons=$arr; else $this->fons=array($arr,$arr);} public function titles($text,$) {$this->tit=$text; $this->sesttit=$style;} public function addrow($a) {$this->arr[]=$a;} public function addrows($arr) {$n=count($arr); for($i=0;$iaddrow($arr[$i]);} public function html() { $cfondos=$this->fons; $titulos=; $t=count($this->tit); for($k=0;$ktit[$k]); } $titulos.=
; $celdas=; $n=count($this->arr); for($i=0;$ifons[$i%2]); $linea=$this->arr[$i]; $m=count($linea); for($j=0;$jsextra,$titulos,$celdas); } public function example() { $tit=array(apellidos,nombre,telefono); $r1=array(garcia,ivan,888); $r2=array(marco,alfonso,555); $x=new xtable(); $x->titles($tit); //take titles array $x->addrows(array($r1,$r2)); // take all rows at same time return $x->html(); //return html code to get/show/save it }}// example$t1=new xtable();echo $t1->example().;$t2=new xtable();for($i=1;$iaddrow(array(odd,$i)); $t2->addrow(array(even,$i+1)); }$t2->background(array(pink,gold));$t2->titles(array(type,#));$t2->extra( style='width:500px; background-color:cyan; color:navy;');echo $t2->html().;$t3=new xtable();for($i=1;$iaddrow(array(5x.$i,5*$i)); }$t3->background(array(olive,maroon));$t3->titles(array(multiplication table,5));$t3->extra(style='border:dotted red 10px; padding-left:4px;padding-right:4px; text-align:right;width:500px; background-color:black; color:white;');echo $t3->html().;$t4=new xtable();$a=array(#);for($i=1;$iaddrow($a);$t4->background(array(pink,gold));$tit=array(); $tit[]=numbers;for($i=1;$ititles($tit);$t4->extra(style='border:solid 1px silver; padding-left:4px;padding-right:4px; text-align:center;width:500px; background-color:cyan; color:navy;');echo $t4->html().;?>