2012-09-03 100 views
-4

我正在尋找一種方式來顯示5-6個貨幣匯率的簡單表格。只是一個簡單的代碼來顯示1美元是多少歐元,挪威克朗,丹麥克朗,英鎊等..顯示5-6貨幣匯率/兌換率的簡單方法?

沒有人有解決這個好辦法?

[解決]我發現了一個很好的解決方案在這裏,如果有人需要這樣的未來: http://www.dynamicguru.com/php/currency-conversion-using-php-and-google-calculator-api/#more-285

這是我如何使用它:

<?php 
function currency($from_Currency,$to_Currency,$amount) { 
$amount = urlencode($amount); 
$from_Currency = urlencode($from_Currency); 
$to_Currency = urlencode($to_Currency); 
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency"; 
$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('"', $rawdata); 
$data = explode('"', $data['3']); 
$var = $data['0']; 
return round($var,1); 
} 
?> 

<strong>Results:</strong><br /> 
100NOK to USD = <?php echo currency("NOK","USD",100); ?><br /> 
100NOK to EUR = <?php echo currency("NOK","EUR",100); ?><br /> 
100NOK to GBP = <?php echo currency("NOK","GBP",100); ?><br /> 
100NOK to SEK = <?php echo currency("NOK","SEK",100); ?><br /> 
100NOK to DKK = <?php echo currency("NOK","DKK",100); ?><br /> 
+0

可能du pxtate http://stackoverflow.com/questions/181990/programmatically-access-currency-exchange-rates?rq=1 – Fluffeh

+0

很多wordpress插件,forex-box,但他們都缺乏一種方法來設置自己的currencys或一種方法來調整設計 – Demilio

回答

0

您可以隨時使用谷歌的貨幣換算

這是一個起點:

http://www.google.com/ig/calculator?hl=en&q=1USD=?EUR 
+0

看起來很有趣,但我怎樣才能提取數據到html?我有點新了 – Demilio

+0

它是json,使用'json_decode()' –

+0

我找到了一個解決方案 - http://www.dynamicguru.com/php/currency-conversion-using-php-and-google-calculator- API /#更-285 – Demilio