Jump to content

file_get_content error


alin19

Recommended Posts

i have a script that worked perfectly a few days ago, and today i get the error:

 

 

Warning: file_get_contents(http://www.bnro.ro/nbrfxrates.xml) [function.file-get-contents]: failed to open stream: No route to host in /opt/lampp/htdocs/curs_val.php on line 7

 

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /opt/lampp/htdocs/curs_val.php:10 Stack trace: #0 /opt/lampp/htdocs/curs_val.php(10): SimpleXMLElement->__construct('') #1 {main} thrown in /opt/lampp/htdocs/curs_val.php on line 10

 

<html>

<?php

$url  = 'http://www.bnro.ro/nbrfxrates.xml';

    $curs = file_get_contents($url);


$xml = new SimpleXMLElement($curs);





foreach( $xml->Body->Cube->Rate as $rate ){

    $final = array();


    foreach( $rate->attributes() as $att => $value ){

        if( $att=='currency' )   $final['currency']   = (string) $value;
        if( $att=='multiplier' ) $final['multiplier'] = (string) $value;
    }
    $final['rate'] = (string) $rate;

    if( empty($final['multiplier']) ) $final['multiplier'] = 1;

    echo $final['currency'].' '.$final['multiplier'].' '.$final['rate'].'</br>';

}


?>
</html>

Link to comment
https://forums.phpfreaks.com/topic/119272-file_get_content-error/
Share on other sites

Manual says about the file_get_contents function:

 

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and List of Supported Protocols/Wrappers for a list of supported URL protocols.

 

http://uk2.php.net/file_get_contents

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.