rougin / gable
A simple HTML table generator in PHP.
dev-master
2025-07-05 07:18 UTC
Requires
- php: >=5.3.0
- psr/http-message: ~1.0
Requires (Dev)
- phpunit/phpunit: ~4.2|~5.7|~6.0|~7.0|~8.0|~9.0
- sanmai/phpunit-legacy-adapter: ~6.1|~8.0
This package is auto-updated.
Last update: 2025-07-05 07:19:25 UTC
README
A simple HTML table generator in PHP.
Installation
Install the package using Composer:
$ composer require rougin/gable
Basic usage
Generate a HTML table using the Table
class:
// table.php use Rougin\Gable\Table; $table = new Table; $table->newColumn(); $table->setCell('Name'); $table->setCell('Age'); $table->newRow(); $table->setCell('Chad'); $table->setCell('25'); $table->newRow(); $table->setCell('Gable'); $table->setCell('25'); echo $table->make();
$ php table.php <table><thead><tr><td>Name</td><td>Age</td></tr></thead><tbody><tr><td>Chad</td><td>25</td></tr><tr><td>Gable</td><td>25</td></tr></tbody></table>
Customization
Each column, row, or even cell can be customized:
// table.php use Rougin\Gable\Table; $table = new Table; $table->newColumn(); $table->setCell('Name', null, null, 2); $table->newColumn(); $table->setEmptyCell(); $table->setCell('Age'); $table->newRow(); $table->setCell('Chad', 'center', 'fw-bold'); $table->setCell('25', 'right'); $table->newRow('fw-bold'); $table->setCell('Gable', 'center', 'fw-bold'); $table->setCell('25', 'right'); echo $table->make();
$ php table.php <table><thead><tr><td colspan="2">Name</td></tr><tr><td></td><td>Age</td></tr></thead><tbody><tr><td align="center" class="fw-bold">Chad</td><td align="right">25</td></tr><tr class="fw-bold"><td align="center" class="fw-bold">Gable</td><td align="right">25</td></tr></tbody></table>
Available methods
Kindly see the following optional arguments for each method from the Table
class:
newColumn($class = null, $style = null, $width = null)
- Adds a new
<tr>
element under<thead>
.
newRow($class = null, $style = null, $width = null)
- Adds a new
<tr>
element under<tbody>
.
setCell($value, $align = null, $class = null, $cspan = null, $rspan = null, $style = null, $width = null)
- Adds a new
<td>
element in either<thead>
or<tbody>
.
Change log
See CHANGELOG for more recent changes.
Development
Includes tools for code quality, coding style, and unit tests.
Code quality
Analyze code quality using phpstan:
$ phpstan
Coding style
Enforce coding style using php-cs-fixer:
$ php-cs-fixer fix --config=phpstyle.php
Unit tests
Execute unit tests using phpunit:
$ composer test