2016-11-22 5 views
0

앱이 다른 국가에 배포되므로 런타임에 설정된 금액을 변환하는 데 필요한 앱이 있습니다.통화 변환

세트 가격을 100 달러로 설정한다고 가정 해 보겠습니다. 그것을 다른 통화로 변환하는 간단한 방법이 있습니까 (장치의 로케일을 기반으로합니다). 내가 구글 금융 계산기를 사용하고

건배

+1

환율이 변동한다는 것을 알고 있습니까? Java를 처리 할 수있는 기능은 없습니다. –

+0

google api : [link] (https://www.google.com/finance/converter?a=1&from=USD&to=INR) 또는 유럽 중앙 은행 api : [link] (http : //www.ecb .europa.eu/stats/eurofxref/eurofxref-daily.xml) 업데이트 된 통화 값 –

답변

0

는 사용자로는 PHP에서이를 사용하여 변환 된 데이터를 가져올 수있는 응용 프로그램과 상호 작용합니다.

function convertCurrency($amount, $from, $to){ 
$url = "https://www.google.com/finance/converter?a=$amount&from=$from&to=$to"; 
$data = file_get_contents($url); 
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted); 
$converted = preg_replace("/[^0-9.]/", "", $converted[1]); 
return round($converted, 3); 
} 

저는 INR 변환기에 USD를 사용하고 있습니다. 호출이 기능

echo convertCurrency(1, "USD", "INR"); 
0

당신은 통화 요금이 변경 될 때마다 flatuating 자바 코드 원인 환율에 의해 .. 당신은 ---이 자동으로 업데이트됩니다이 API를 사용할 수 할 수없는

<?php 
$from = $_POST["from"]; 
$to = $_POST["to"]; 
$amount = $_POST["amount"]; 
$rawData = currencyConvert($from,$to,$amount); 
$regex = '#\<span class=bld\>(.+?)\<\/span\>#s'; 
preg_match($regex, $rawData, $converted); 
$result = $converted[0]; 
preg_match('!\d+(?:\.\d+)?!', $result, $result); 
echo $result[0]; 

function currencyConvert($from,$to,$amount){ 
    $url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to"; 
    $request = curl_init(); 
    $timeOut = 0; 
    curl_setopt ($request, CURLOPT_URL, $url); 
    curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"); 
    curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut); 
    $response = curl_exec($request); 
    curl_close($request); 
    return $response; 
    } 

?> 
관련 문제