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 = Parser::new()
->ignoreTableHeader()
->ignoreXmlErrors()
->withoutFormatter()
->tableCaption('This is a beautiful table');
use Bakame\HtmlTable\Parser;
$parser = Parser::new()->tablePosition('table-id'); // parses the <table id='table-id'>
$parser = Parser::new()->tablePosition(3); // parses the 4th table of the page
$parser = Parser::new()->tableXPathPosition("//main/div/table");
//parse the first table that matches the xpath expression
use Bakame\HtmlTable\Parser;
$parser = Parser::new()->tableCaption('this is a generated caption');
$parser = Parser::new()->tableCaption(null); // remove any default caption set
use Bakame\HtmlTable\Parser;
use Bakame\HtmlTable\Section;
$parser = Parser::new()->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 = Parser::new()->ignoreTableHeader(); // no table header will be resolved
$parser = Parser::new()->resolveTableHeader(); // will attempt to resolve the table header
use Bakame\HtmlTable\Parser;
use Bakame\HtmlTable\Section;
$parser = Parser::new()->tableHeader(['rank', 'team', 'winner']);
use Bakame\HtmlTable\Parser;
use Bakame\HtmlTable\Section;
$parser = Parser::new()->tableHeader([3 => 'rank', 7 => 'winner', 5 => 'team']);
// only 3 column 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 = Parser::new()->t tr children and tfoot are not
use Bakame\HtmlTable\Parser;
$parser = Parser::new()->withFormatter($formatter); // attach a formatter to the parser
$parser = Parser::new()->withoutFormatter(); // 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 = Parser::new()->ignoreXmlErrors(); // ignore the XML errors
$parser = Parser::new()->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.