I was using a code that always worked for me when i need to get external html content but, since yesterday, the code no longer works.
Here´s the code setup
ini_set('display_errors', 1);
$url ='https://www3.bcb.gov.br/ptax_internet/consultarTodasAsMoedas.do?method=consultaTodasMoedas';
$site = file_get_contents($url);
This link is a Currency Converter from Brazil Central Bank and have daily updates (Business Days).
I Need to get the USD and EUR values from this page, when i try to get values inside the Table it return empty but when i get values inside a div everything work as expected.
If i go to the page Source Code i can see:
<tr class="fundoPadraoBClaro2">
<td align="CENTER">220</td>
<td align="CENTER">A</td>
<td align="CENTER">USD</td>
<td align="right">2,2743</td>
<td align="right">2,2748</td>
<td align="right">1,0000</td>
<td align="right">1,0000</td>
</tr>
To get the Dollar Value i use:
$data1 = explode('<td align="CENTER">USD</td><td align="right">', $site);
$data2 = explode('</td>',$data1[1]);
$usd = $data2[0];
But don´t work, this returns empty values.
But if i use the same code to get contents inside a DIV everything Works ok.
Source Code:
<div align="center">
<strong>Cotações de todas as moedas no dia 09/08/2013 às 13:00 (horário de Brasília), conforme fechamento PTAX.</strong>
</div>
PHP Code:
$data1 = explode('todas as moedas no dia', $site);
$data2 = explode('conforme fechamento PTAX.',$data1[1]);
$result = $data2[0];
I get what i expected - "09/08/2013 às 13:00 (horário de Brasília)"
Can anyone tell me what i´m missing ?