bystro / html-table-converter
Converts HTML table to other format
Installs: 65
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 1
Open Issues: 0
pkg:composer/bystro/html-table-converter
Requires
- php: ^7.0|^8.0
Requires (Dev)
- phpunit/phpunit: ^6.0|^7.0|^8.0|^9.0
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2025-09-28 20:31:13 UTC
README
Author: Krzysztof Kubacki
Date: 04-03-2019
About
Converts HTML table to other format
This project is in ALPHA, meaning it is not fully functional!
Inspired by project https://github.com/tremblay/HTML-Table-to-JSON
Example
Given we have table bellow
| First name | Last name | Points |
|---|---|---|
| Jill | Smith | 50 |
| Eve | Jackson | 94 |
When we run the code bellow
<?php $converter = HtmlTableConverter\HtmlTableConverterFactory::fromHtml($tableHtml); var_dump($converter->convert());
Then will get the following result
array(3) {
[0] =>
array(3) {
[0] =>
string(10) "First name"
[1] =>
string(9) "Last name"
[2] =>
string(6) "Points"
}
[1] =>
array(3) {
'First name' =>
string(4) "Jill"
'Last name' =>
string(5) "Smith"
'Points' =>
string(9) "<b>50</b>"
}
[2] =>
array(3) {
'First name' =>
string(3) "Eve"
'Last name' =>
string(7) "Jackson"
'Points' =>
string(9) "<b>94</b>"
}
}
Stripping HTML tags from column values
<?php $converter = HtmlTableConverter\HtmlTableConverterFactory::fromHtml($tableHtml); $converter->stripTagsFromColumnValues(); var_dump($converter->convert());
array(3) {
[0] =>
array(3) {
[0] =>
string(10) "First name"
[1] =>
string(9) "Last name"
[2] =>
string(6) "Points"
}
[1] =>
array(3) {
'First name' =>
string(4) "Jill"
'Last name' =>
string(5) "Smith"
'Points' =>
- string(9) "<b>50</b>"
+ string(2) "50"
}
[2] =>
array(3) {
'First name' =>
string(3) "Eve"
'Last name' =>
string(7) "Jackson"
'Points' =>
- string(9) "<b>94</b>"
+ string(2) "94"
}
}
Removing header values
<?php $converter = HtmlTableConverter\HtmlTableConverterFactory::fromHtml($tableHtml); $converter->doNotIncludeHeaderRowInResult(); var_dump($converter->convert());
array(2) {
- [0] =>
- array(3) {
- [0] =>
- string(10) "First name"
- [1] =>
- string(9) "Last name"
- [2] =>
- string(6) "Points"
- }
[0] =>
array(3) {
'First name' =>
string(4) "Jill"
'Last name' =>
string(5) "Smith"
'Points' =>
string(9) "<b>50</b>"
}
[1] =>
array(3) {
'First name' =>
string(3) "Eve"
'Last name' =>
string(7) "Jackson"
'Points' =>
string(9) "<b>94</b>"
}
}
Converting to JSON
<?php $converter = HtmlTableConverter\HtmlTableConverterFactory::fromHtml($tableHtml); $converter->convert(\HtmlTableConverter\Converter\Type::JSON);
Output format supported:
- array
- json
Install
Composer
In command line
composer require bystro/html-table-converter
or composer.json
"require": {
"bystro/html-table-converter": "^1.0"
}