Web服务,webservicex货币转换器php

时间:2014-05-14 08:37:03

标签: php converter currency

我正在尝试使用http://www.webservicex.com/CurrencyConvertor.asmx?WSDL的网络服务。 我可以用两种货币换算货币,即" NZD" " GBP"但是我需要有两个下拉框来获取所有货币代码并将它们作为选项放入。我不知道如何获得这些货币代码。谢谢

php的代码是     

/* Get the values for the amount and currencies */
$amount = $_POST['amount'];
$currency1 = $_POST['currency1'];
$currency2 = $_POST['currency2'];

// Set the url for the webservice.
$wsdl="http://www.webservicex.com/CurrencyConvertor.asmx?WSDL";

// Make soap client.
$client = new SoapClient( $wsdl );

// Set up the parameters
$country=array();

// Set the country variable to the country codes.
$country['FromCurrency']= $currency1;
$country['ToCurrency'] = $currency2;

// Use the client to run the required operation and receive a response
$result = $client->ConversionRate($country);


// Print the results.
print("<br /> The exchange rate from <b>".$country['FromCurrency']."</b> to    <b>".$country['ToCurrency']."</b> is: <b>". $result->ConversionRateResult)."</b><br />";
}
?>

在html中我有两个选择框,我需要填写国家代码(&#39; NZD&#39;,&#39; GBP&#39;等),这将是currency1和currency2变量。我想从webservicex获取这些货币代码作为数组或我可以用来填充选择框的东西。

1 个答案:

答案 0 :(得分:0)

您可以使用此库https://github.com/florianv/swap。它支持多个提供商,并将为您节省低级别的东西。