samoussa / phphtmltable
在PHP中操作HTML表格
1.0.3
2019-04-26 06:20 UTC
Requires
- php: >=7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.12
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7
This package is not auto-updated.
Last update: 2024-09-29 05:49:22 UTC
README
PHP HTML TABLE
此存储库允许在PHP中操作HTML表格
概念
该项目涉及以下概念
https://w3schools.org.cn/html/html_tables.asp
要求
PHP 7.0或更高版本。
安装
通过将仓库添加到您的composer.json文件中将其包含到您的项目中。
composer require samoussa/phphtmltable
用法
HTML表格 - 添加标题
$table = new \Samoussa\PhpHtmlTable\table(); $table->setCaption("My table") ->addTr([1, "2", "tree"]) ->addTr([4, "5", ["six",["style" => "color:red;"]]]) ->render(true);
定义HTML表格
$table = new \Samoussa\PhpHtmlTable\table(["style" => "width:100%"]); $tr = new \Samoussa\PhpHtmlTable\tr(); $tr->addTh("Firstname") ->addTh("Lastname") ->addTh("Age"); $table->addTr($tr) ->addTr(["Jill", "Smith", "50"]) ->addTr([new td("Eve"), new td("Jackson"), new td("94",["style" => "color:red;"])]) ->render(true);
HTML表格 - 跨多列的单元格
$table = new \Samoussa\PhpHtmlTable\table(["style" => "width:100%"]); $tr = new \Samoussa\PhpHtmlTable\tr(); $tr->addTh("Name") ->addTh(["Telephone", ["colspan" => 2]]); $table->addTr($tr) ->addTr(["Bill Gates", 55577854, 55577855]) ->render(true);
HTML表格 - 跨多行的单元格
$table = new \Samoussa\PhpHtmlTable\table(["style" => "width:100%"]); $table->addTr([new \Samoussa\PhpHtmlTable\th('Telephone', ['rowspan' => 2]), 555778545]); $tr = new \Samoussa\PhpHtmlTable\tr(); $tr->addTh("Name") ->addTd("Bill Gates"); $table->addTr($tr) ->addTr(['55577855']) ->render(true);
为单个表格指定特殊样式(例如Twitter Bootstrap)3
$table = new \Samoussa\PhpHtmlTable\table(['class' => 'table table-striped']); $table->addTr([1, "2", "tree"]) ->addTr([4, "5", ["six", ["style" => "color:red;"]]]) ->render(true);
指定用于格式化的表格中的一组一个或多个列
$table = new \Samoussa\PhpHtmlTable\table(); $table->addTr(new \Samoussa\PhpHtmlTable\tr(['ISBN', 'Title', 'Price'])) ->addTr([3476896, 'My first HTML', "$53"]) ->addTr([4, '5', "six"]) ->colgroup() ->addCol(new \Samoussa\PhpHtmlTable\col(['span' => 2, 'style' => 'background-color:red'])) ->addCol(new \Samoussa\PhpHtmlTable\col(['style' => 'background-color:yellow'])); $table->render(true);
https://bootstrap.ac.cn/docs/4.0/content/tables/#table-head-options
#A Special Style for One Table (Exemple twitter bootstrap) 4 $table = new \Samoussa\PhpHtmlTable\table(["class" => "table"]); $table->thead(['class' => 'thead-light']) ->addTr( [ new \Samoussa\PhpHtmlTable\th('#', ['scope' => "col"]), new \Samoussa\PhpHtmlTable\th('First', ['scope' => "col"]), new \Samoussa\PhpHtmlTable\th('Last', ['scope' => "col"]), new \Samoussa\PhpHtmlTable\th('Handle', ['scope' => "col"]), ] ); $table->tbody() ->addTr([new \Samoussa\PhpHtmlTable\th('1', ['scope' => "col"]), 'Mark', 'Otto', '@mdo']) ->addTr([new \Samoussa\PhpHtmlTable\th('2', ['scope' => "col"]), 'Jacob', 'Thornton', '@fat']) ->addTr([new \Samoussa\PhpHtmlTable\th('3', ['scope' => "col"]), 'Larry', 'the Bird', '@twitter']); $table->render(true);