将php数组输出html表格的方法
代码如下: class 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("#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,$style="") {$this->tit=$text; $this->sesttit=$style;} public function addrow($a) {$this->arr[]=$a;} public function addrows($arr) {$n=count($arr); for($i=0;$i<$n;$i++) $this->addrow($arr[$i]);} public function html() { $cfondos=$this->fons; $titulos=" for($k=0;$k<$t;$k++) { $titulos.=sprintf(" %s | ",$this->tit[$k]);} $titulos.=" for($i=0;$i<$n;$i++) { $celdas.=sprintf(" $linea=$this->arr[$i]; $m=count($linea); for($j=0;$j<$m;$j++) $celdas.=sprintf(" %s | $celdas.="return sprintf(" } 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 } }
"; $t2=new xtable(); "; $t3=new xtable(); "; $t4=new xtable(); "; ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |