I found this topic: How to parse this table and extract data from it? Which probably is the answer for my problem, I want to the same thing - parse some external table, extract data and print this data on my webpage. @Yoshi gives perfect answer, but when I trying to use this code, I am getting empty array
Array ( )
I don't know why this doesn't work? I trying to use the same example
<?php
$dom = new DomDocument;
$dom->loadHtmlFile('http://www.nbs.rs/kursnaListaModul/srednjiKurs.faces?lang=lat');
$xpath = new DomXPath($dom);
// collect header names
$headerNames = array();
foreach ($xpath->query('//table[@id="index:srednjiKursLista"]//th') as $node) {
$headerNames[] = $node->nodeValue;
}
// collect data
$data = array();
foreach ($xpath->query('//tbody[@id="index:srednjiKursLista:tbody_element"]/tr') as $node) {
$rowData = array();
foreach ($xpath->query('td', $node) as $cell) {
$rowData[] = $cell->nodeValue;
}
$data[] = array_combine($headerNames, $rowData);
}
print_r($data);
?>