function _background_process_ass_parse_table in Background Process 7.2
Same name and namespace in other branches
- 8 background_process_ass/background_process_ass.module \_background_process_ass_parse_table()
- 6 background_process_ass/background_process_ass.module \_background_process_ass_parse_table()
- 7 background_process_ass/background_process_ass.module \_background_process_ass_parse_table()
Converts an HTML table into an associative array.
Parameters
$html: HTML containing table.
Return value
array Table data.
1 call to _background_process_ass_parse_table()
- background_process_ass_get_server_status in background_process_ass/
background_process_ass.module - Get apache extended server status.
File
- background_process_ass/
background_process_ass.module, line 349 - @todo Implement admin interface. @todo Fix runtime check of running process.
Code
function _background_process_ass_parse_table($html) {
// Find the table
preg_match_all("/<table.*?>.*?<\\/[\\s]*table>/s", $html, $table_htmls);
$tables = array();
foreach ($table_htmls[0] as $table_html) {
// Get title for each row
preg_match_all("/<th.*?>(.*?)<\\/[\\s]*th>/s", $table_html, $matches);
$row_headers = $matches[1];
// Iterate each row
preg_match_all("/<tr.*?>(.*?)<\\/[\\s]*tr>/s", $table_html, $matches);
$table = array();
foreach ($matches[1] as $row_html) {
$row_html = preg_replace("/\r|\n/", '', $row_html);
preg_match_all("/<td.*?>(.*?)<\\/[\\s]*td>/", $row_html, $td_matches);
$row = array();
for ($i = 0; $i < count($td_matches[1]); $i++) {
$td = strip_tags(html_entity_decode($td_matches[1][$i]));
$i2 = isset($row_headers[$i]) ? $row_headers[$i] : $i;
$row[$i2] = $td;
}
if (count($row) > 0) {
$table[] = $row;
}
}
$tables[] = $table;
}
return $tables;
}