HTML Tables (Colspan Rowspan) Replacer / Exporter

by Hugo Maugey

Copy your HTML containing table(s)

(optionaly with colspan and/or rowspan)

View / Save your result as HTML or JSON

(with colspan & rowspan replaced)

Why / How to use Plugin ?


  • PHP Server Side Script bundled with web interface (available as free demo just above)
  • Export Full table cells content (HTML, not just text)
  • Export HTML tables as JSON Objects taking care of colspan and rowspan replacement values.
  • Replace Tables in an HTML document by their equivalent without rowspan and colspan, preserving all table attributes.
  • Ease process of extrating / scraping HTML tables data in your PHP scripts.
  • Modify highly modular / commented code to suit your needs.

Use in Browser

Direct Access to the plugin web interface (same as online demo)
Alternatively, you can set up a virtual host on your server and access plugin through it !

Use in PHP

# Require plugin class
require_once __DIR__ . '/HtmlTable.class.php';

# Get HTML from file or URL
$html = file_get_content('YOUR_FILE_PATH_OR_URL');

# Instanciate Plugin with HTML 
$HtmlTable = new HtmlTable($html);

# First example : replace all tables in document
# 1. Optional output file (default is null)
$output_file = null; // Define an optional output_file. If output_file is a valid file path, HTML result will be saved in it
# 2. Process
$html = $HtmlTable->html_replace_tables($output_file);
# 3. Display result
echo 'Transformed HTML : ' . $html;

# Second example : extract table(s) as array(s)
# 1. Optional : Customize which table(s) you would like to extract giving XPath request (default to '//body//table' : extract all tables in document)
$xpath_query = '//body//table[2]'; // only second table in document
$xpath_query = '//body//table[@class="my_class"]'; // all tables with the my_class class
$xpath_query = '//body//table[@id="my_id"]';// all tables with the my_id id
# 2. Process
$table_as_array = $HtmlTable->html_tables_to_arrays($xpath_query);
# 3. Display result

If you buy the plugin, you will have access to the PHP documentation generated by

You can (re)generate it by yourself :
phpdoc -f YOUR_PATH/convert-html-table/php/class/HtmlTable.class.php -t YOUR_PATH/convert-html-table/phpdoc/


Use as API Service

// Call your API endpoint by POST with (Javascript XMLHttpRequest, JQuery $.post, your favorite framework call)
var response = CALL 'php/api/endpoint.php';

// Response is in JSON format
var response = JSON.parse(response);

// Response format is as follows
response.status => success | error
response.message => potential error message => HTML response => JSON response
Server Side API Endpoint Example is provided if you buy the plugin (in php/api folder) !


This Tool has been build on top of
- PHP > 5.x : no need of any PHP modules or depencies. Tested on
- Twitter Bootstrap 3.3.6 : the famous framework
- JQuery 2.2.0 : what ?
- FileSaver.js : gives ability to easily export files in browser.
- Blob.js : gives support to browser without saveAs functionnality to work