php数组怎么输出html表格

这篇文章主要介绍了php数组怎么输出html表格的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇php数组怎么输出html表格文章都会有所收获,下面我们一起来看看吧。

成都创新互联公司是一家业务范围包括IDC托管业务,雅安服务器托管、主机租用、主机托管,四川、重庆、广东电信服务器租用,大邑服务器托管,成都网通服务器托管,成都服务器租用,业务范围遍及中国大陆、港澳台以及欧美等多个国家及地区的互联网数据服务公司。

代码如下:

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="";
??$t=count($this->tit);
??for($k=0;$k<$t;$k++)
??{
???$titulos.=sprintf("%s",$this->tit[$k]);
??}
??$titulos.="";

??$celdas="";
??$n=count($this->arr);
??for($i=0;$i<$n;$i++)
??{
???$celdas.=sprintf("",$this->fons[$i%2]);
???$linea=$this->arr[$i];
???$m=count($linea);
???for($j=0;$j<$m;$j++)
????$celdas.=sprintf("%s","",$linea[$j]);
???$celdas.="";
??}
??return sprintf("

%s%s
",$this->sextra,$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;$i<=10;$i+=2)
?{
??$t2->addrow(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;$i<=6;$i++)
?{
??$t3->addrow(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;$i<=10;$i++)
?{
??$a[]=$i;
?}
$t4->addrow($a);
$t4->background(array("pink","gold"));
$tit=array(); $tit[]="Numbers";
for($i=1;$i<=10;$i++) $tit[]="#";
$t4->titles($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()."


";
?>

关于“php数组怎么输出html表格”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“php数组怎么输出html表格”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注创新互联行业资讯频道。


本文题目:php数组怎么输出html表格
分享地址:http://scyanting.com/article/jpdcoj.html