的file_get_contents(); 不再使用html表?

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 ?

The problem is that you're not taking the whitespace between <td align="CENTER">USD</td> and <td align="right"> into account.

This is a perfect situation where you would use regular expressions instead of string manipulations:

Code

$matches = array();
if (preg_match("/USD<\\/td>\\s+<td[^>]*>(?<usd_value>[0-9,.-]*)<\\/td>/i", $site, $matches))
    echo $matches["usd_value"];

The regex searches USD followed by </td>, followed by whitespace, then <td...> tag. Everything between that <td...> and next </td> that looks like a number is captured into the group with name usd_value

Output

2,2743

I found an error: $data2 = explode('</td>',$data[1]);

should be:

$data2 = explode('</td>',$data1[1]);