1. Go to this page and download the library: Download bakame/html-table library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Bakame\HtmlTable\Parser;
$parser = (new Parser())->tablePosition('table-id'); // parses the <table id='table-id'>
$parser = (new Parser())->tablePosition(3); // parses the 4th table of the page
$parser = (new Parser())->tableXPathPosition("//main/div/table");
//parse the first table that matches the xpath expression
use Bakame\HtmlTable\Parser;
$parser = (new Parser())->tableCaption('this is a generated caption');
$parser = (new Parser())->tableCaption(null); // remove any default caption set
use Bakame\HtmlTable\Parser;
use Bakame\HtmlTable\Section;
$parser = (new Parser())->tableHeaderPosition(Section::Thead, 3);
// header is the 4th row in the <thead> table section
use Bakame\HtmlTable\Section;
enum Section
{
case thead;
case tbody;
case tfoot;
case tr;
}
use Bakame\HtmlTable\Parser;
$parser = (new Parser())->ignoreTableHeader(); // no table header will be resolved
$parser = (new Parser())->resolveTableHeader(); // will attempt to resolve the table header
use Bakame\HtmlTable\Parser;
use Bakame\HtmlTable\Section;
$parser = (new Parser())->tableHeader(['rank', 'team', 'winner']);
use Bakame\HtmlTable\Parser;
use Bakame\HtmlTable\Section;
$parser = (new Parser())->tableHeader([3 => 'rank', 7 => 'winner', 5 => 'team']);
// only 3 columns will be extracted the 4th, 6th and 8th columns
// and re-arrange as 'rank' first and 'team' last
// if a column is missing its value will be PHP `null` type
use Bakame\HtmlTable\Parser;
use Bakame\HtmlTable\Section;
$parser = (new Parser())->t tr children and tfoot are not
use Bakame\HtmlTable\Parser;
$parser = (new Parser())->withFormatter($formatter); // attach a formatter to the parser
$parser = (new Parser())->withFormatter(null); // removed the attached formatter if it exists
function (array $record): array;
$formatter = fn (array $record): array => array_map(strtolower(...), $record);
// the following formatter will convert all the fields from your table to lowercase.
$formatter = function (array $record): array {
$record['count'] = (int) $record['count'];
return $record;
}
// the following formatter will convert the data of all count column into integer..
use Bakame\HtmlTable\Parser;
$parser = (new Parser())->ignoreXmlErrors(); // ignore the XML errors
$parser = (new Parser())->failOnXmlErrors(3); // throw on XML errors
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.