使用谷歌金融和雅虎金融货币转换为代码点火器。工作了2-4个月,但现在突然之间转换变得禁用??。
我的代码片段(帮助文件代码):
<?php
if (!function_exists('convertCurrency')) {
function convertCurrency($amount,$from_Currency,$to_Currency) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$get = @file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
$get = explode("<span class=bld>",$get);
$get = explode("</span>",$get[1]);
$converted_currency = preg_replace("/[^0-9\.]/", null, $get[0]);
return number_format($converted_currency,2,'.','');
}
}在控制器和视图文件中调用该函数,如下所示:
<?php echo convertCurrency($amount, "INR", "USD");?>工作了2-4个月,但现在它在??之间失去了功能。
我也尝试过卷曲,但没有得到链接.的响应。
请建议我正确的想法??
发布于 2018-03-20 10:03:04
下面的代码可以工作。试试看:)
$url = "http://www.xe.com/currencyconverter/convert/?
Amount=1&From=USD&To=INR";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode('uccResultAmount', $rawdata);
@$data = explode('uccToCurrencyCode', $data[1]);
$amount = preg_replace('/[^0-9,.]/', '', $data[0]);发布于 2018-04-19 06:47:59
您还可以使用:
$res = file_get_contents("https://finance.google.com/bctzjpnsun/converter?a=1&from=USD&to=CAD");这是谷歌计算器,并将工作。
现在您必须解析这个响应:
$res = explode("<span class=bld>",$res);
$res = explode("</span>",$res[1]);
$rate= preg_replace("/[^0-9\.]/", null, $get[0]);https://stackoverflow.com/questions/49356238
复制相似问题