file_get_contents [closed]

-2

How to get the quote value through the file get contents from the following page: link

    
asked by anonymous 09.12.2016 / 15:40

1 answer

1

I made a code here and got the result:

$html = file_get_contents( "https://www.google.com/finance?q=USDBRL&ei=tb1KWOHWLMX_mAGJyLnIBw" );
$content = new DOMDocument();
@$content->loadHTML( $html );
$itens = $content->getElementsByTagName( "span" );

$cotacao = null;

foreach( $itens as $item ) {

    if ( stripos( $item->getAttribute( "class"), "pr" ) !== false )
        $cotacao = str_replace( "1 USD = ", "", $item->nodeValue );
}

echo trim( $cotacao );
    
09.12.2016 / 16:46