亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

將php數(shù)組輸出html表格的方法

 更新時間:2014年02月24日 11:21:53   作者:  
這篇文章主要介紹了將php數(shù)組輸出html表格的方法,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

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

  $celdas="";
  $n=count($this->arr);
  for($i=0;$i<$n;$i++)
  {
   $celdas.=sprintf("<tr style='background-color:%s'>",$this->fons[$i%2]);
   $linea=$this->arr[$i];
   $m=count($linea);
   for($j=0;$j<$m;$j++)
    $celdas.=sprintf("<td  %s>%s</td>","",$linea[$j]);
   $celdas.="</tr>";
  }
  return sprintf("<table cellpadding='0' cellspacing='0' border='1' %s>%s%s</table>",$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()."<hr />";

$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()."<hr />";

$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()."<hr />";

$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()."<hr />";
?>

相關(guān)文章

  • ThinkPHP連接數(shù)據(jù)庫的方式匯總

    ThinkPHP連接數(shù)據(jù)庫的方式匯總

    這篇文章主要介紹了ThinkPHP連接數(shù)據(jù)庫的方式,包括項目配置文件定義、DSN方式傳參、數(shù)組傳參、模型類里定義等,非常具有實用價值,需要的朋友可以參考下
    2014-12-12
  • PHP文章采集URL補全函數(shù)(FormatUrl)

    PHP文章采集URL補全函數(shù)(FormatUrl)

    寫此函數(shù)作用就是為了開發(fā)采集程序,采集文章的時候會經(jīng)常遇到頁面里的路徑是 相對路徑 或者 絕對根路徑 不是 絕對全路徑 就無法收集URL
    2012-08-08
  • WHOOPS PHP調(diào)試庫的使用

    WHOOPS PHP調(diào)試庫的使用

    下面小編就為大家?guī)硪黄猈HOOPS PHP調(diào)試庫的使用。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • php file_get_contents函數(shù)輕松采集html數(shù)據(jù)

    php file_get_contents函數(shù)輕松采集html數(shù)據(jù)

    PHP手冊里是這么解釋的:file_get_contents — 將整個文件讀入一個字符串,于是可以很容易的獲取其他站的信息,再用正則加以變換,再做一些判斷和設(shè)定,就OK了,不多說了,放代碼,我基本都做了解釋的。
    2010-04-04
  • 摘自織夢CMS中的圖片處理類

    摘自織夢CMS中的圖片處理類

    這篇文章主要介紹了摘自織夢CMS中的圖片處理類,通過面向?qū)ο蟮姆绞捷^為詳細(xì)的實現(xiàn)了php針對圖片的縮略圖生成及水印添加等操作技巧,非常具有實用價值,需要的朋友可以參考下
    2015-08-08
  • thinkPHP5.0框架簡單配置作用域的方法

    thinkPHP5.0框架簡單配置作用域的方法

    這篇文章主要介紹了thinkPHP5.0框架簡單配置作用域的方法,簡單分析了thinkPHP5.0作用域的功能與配置技巧,需要的朋友可以參考下
    2017-03-03
  • PHP快速導(dǎo)出百萬級數(shù)據(jù)到CSV或者EXCEL文件

    PHP快速導(dǎo)出百萬級數(shù)據(jù)到CSV或者EXCEL文件

    這篇文章主要介紹了PHP快速導(dǎo)出百萬級數(shù)據(jù)到CSV或者EXCEL文件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • 個人寫的PHP驗證碼生成類分享

    個人寫的PHP驗證碼生成類分享

    這篇文章主要介紹了個人寫的PHP驗證碼生成類分享,此驗證碼類直接拿去就可以用,也可以用來學(xué)習(xí)和分析,需要的朋友可以參考下
    2014-08-08
  • ThinkPHP5.0框架驗證碼功能實現(xiàn)方法【基于第三方擴(kuò)展包】

    ThinkPHP5.0框架驗證碼功能實現(xiàn)方法【基于第三方擴(kuò)展包】

    這篇文章主要介紹了ThinkPHP5.0框架驗證碼功能實現(xiàn)方法,結(jié)合實例形式分析了thinkPHP5基于第三方擴(kuò)展包實現(xiàn)驗證碼功能相關(guān)操作技巧,需要的朋友可以參考下
    2019-03-03
  • Laravel開啟跨域請求的方法

    Laravel開啟跨域請求的方法

    今天小編就為大家分享一篇Laravel開啟跨域請求的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10

最新評論