实施雅虎货币转换器时出错

<?php   error_reporting(0); 
    $currency_code = $_GET['currency_code'];    
    $currency_opt = strtoupper($currency_code)."INR";   
    $jsn_response = file_get_contents('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22' .$currency_opt. '%22%29&format=json&env=store://datatables.org/alltableswithkeys&callback='); 

    $currencyrate_arr = json_decode($jsn_response, true);

    $currency_rate = $currencyrate_arr['query']['results']['rate']['Rate']; 
    //var_dump($currency_rate);
    if($currency_rate > 0){     
        echo $currency_text = $currency_rate;   
    }
    else{       
        echo $currency_text = "SORRY! ERROR..";     
    }
?>

It was working fine but now I am getting error while using this piece of code for currency conversion.

The script is working for me, and produces correct results.

If you are receiving an error, it's either because of a server configuration, or an API limit.

You can check https://developer.yahoo.com/yql/faq/

Rate limits in YQL are based on your authentication. If you use IP-based authentication, then you are limited to 2,000 calls/hour/IP to the public YQL Web service URL (/v1/public/*)

If you need to exceed the 2000 calls per hour limit, read the above link for more information.

PS: If you want to debug, set:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Edit: Since allow_url_fopen is disabled, you can't use file_get_contents on outside URLs, but you can still use CURL.

So just replace the file_get_contents with:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20%28%22' .$currency_opt. '%22%29&format=json&env=store://datatables.org/alltableswithkeys&callback=');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$jsn_response = curl_exec($ch);
curl_close($ch);