项目作者: lib16

项目描述 :
lib16 RSS Builder is a PHP 8 library for creating HTML5 documents.
高级语言: PHP
项目地址: git://github.com/lib16/html-builder-php.git
创建时间: 2020-12-27T17:10:54Z
项目社区:https://github.com/lib16/html-builder-php

开源协议:MIT License

下载


Lib16 HTML Builder for PHP 8

A library for creating HTML5 written in PHP 8.

Build Status
Coverage

Installation with Composer

This package is available on packagist,
therefore you can use Composer to install it.
Run the following command in your shell:

  1. composer require lib16/html dev-main

Basic Usage

Build your tables with this library:

  1. <?php
  2. require_once 'vendor/autoload.php';
  3. use Lib16\HTML\Table;
  4. $data = [
  5. ['model' => 'Panther', 'city' => 'Berlin', 'quantity/store' => 20],
  6. ['model' => 'Panther', 'city' => 'Berlin', 'quantity/store' => 12],
  7. ['model' => 'Panther', 'city' => 'Cologne', 'quantity/store' => 12],
  8. ['model' => 'Lion', 'city' => 'Cologne', 'quantity/store' => 12],
  9. ['model' => 'Lion', 'city' => 'Hamburg', 'quantity/store' => 15],
  10. ['model' => 'Lion', 'city' => 'Hamburg', 'quantity/store' => 15],
  11. ['model' => 'Lion', 'city' => 'Munich', 'quantity/store' => 15],
  12. ];
  13. $table = Table::create('Availability')->setClass('t1');
  14. $table->thead()->tr()->thn('model', 'city', 'quantity/store');
  15. $table->bodies($data);
  16. print $table;
  17. // change order
  18. $keys = ['city', 'model', 'quantity/store'];
  19. $table = Table::create('Availability')->setClass('t1');
  20. $table->thead()->tr()->headerCells($keys);
  21. $table->bodies($data, ...$keys);
  22. print $table;
  23. // row by row
  24. $table = Table::create('Availability')->setClass('t2');
  25. $table->thead()->tr()->thn('model', 'city', 'quantity/store');
  26. foreach ($data as $row) {
  27. $table->tr()->dataCells($row);
  28. }
  29. print $table;
  30. ?>
  31. <style>
  32. body, * {
  33. font-family: source serif pro, serif;
  34. }
  35. caption, th {
  36. font-family: source sans pro, sans-serif;
  37. }
  38. caption {
  39. margin: 0.5em;
  40. }
  41. td, th {
  42. text-align: left;
  43. vertical-align: text-top;
  44. padding: 0.5em;
  45. border: 1px solid rgb(0, 51, 102);
  46. }
  47. td:last-child {
  48. text-align: right;
  49. }
  50. th {
  51. color: white;
  52. background-color: rgba(0, 51, 102, 1);
  53. font-weight: normal;
  54. }
  55. .t1 tbody,
  56. .t2 tr {
  57. background-color: rgba(51, 102, 0, 0.2);
  58. }
  59. .t1 tbody:nth-child(2n),
  60. .t2 tr:nth-child(2n) {
  61. background-color: rgba(52, 102, 0, 0.3);
  62. }
  63. table {
  64. border-collapse: collapse;
  65. margin: 2em;
  66. float: left;
  67. }
  68. </style>