I am trying to extract the headers table from this url: https://www4.bcb.gov.br/pec/poupanca/poupanca.asp
Unfortunately, they use a "non-standard" html table where instead of rowspan they used a (bizarre) table inside the first row ...
So I would like to extract dynamically this header in an array of 8 items like this (merging the the headers with two rows size):
$columns_extracted_result = [
'Data',
'DataFim',
'Depósitos até 03.05.2012 - Remuneração básica ',
'Depósitos até 03.05.2012 - Remuneração adicional',
'Depósitos até 03.05.2012 - Remuneração total',
'Depósitos a partir de 04.05.2012 (*) -Remuneração básica',
'Depósitos a partir de 04.05.2012 (*) - Remuneração adicional',
'Depósitos a partir de 04.05.2012 (*) - Remuneração total'
];
And after that, create a array where the keys will be the $columns_extracted_result like:
$table = [
[
'Data' => '26/04/2022',
'DataFim' => '26/05/2022',
'Depósitos até 03.05.2012 - Remuneração básica' => '0,1538'
//...
],
[
'Data' => '27/04/2022',
'DataFim' => '27/05/2022',
'Depósitos até 03.05.2012 - Remuneração básica' => '0,1568'
//...
]
];
How Can I achieve this using DomXpath ?

Solution
get_columns
The
get_columnsfunction returns a list of columns as defined in the table headers:get_rows
The
get_rowsfunction returns the complete data set, see code and output:Complete code
Output