-4

我正在寻找一种方法来显示一个包含 5-6 种货币汇率的简单表格。只需一个简单的代码即可显示 1 美元在欧元、挪威克朗、丹麦克朗、英镑等中的价值...

有没有人有解决这个问题的好方法?

[已解决] 如果将来有人需要,我在这里找到了一个很好的解决方案: 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 />
4

1 回答 1

0

You can always use Google's Currency converter

Here is a start point:

http://www.google.com/ig/calculator?hl=en&q=1USD=?EUR
于 2012-09-03T07:50:24.117 回答