任何人都可以为我提供解决方案。如何将货币AED转换为美元,然后再将其转换为PayPal。
答案 0 :(得分:2)
您只需使用Google
即可尝试
var_dump(simpleConvert("AED","USD",1));
输出
array
'1.000000' => string '0.272257' (length=8)
使用的功能
function simpleConvert($from,$to,$amount)
{
$content = file_get_contents('https://www.google.com/finance/converter?a='.$amount.'&from='.$from.'&to='.$to);
$doc = new DOMDocument;
@$doc->loadHTML($content);
$xpath = new DOMXpath($doc);
$result = $xpath->query('//*[@id="currency_converter_result"]/span')->item(0)->nodeValue;
return $result;
}
答案 1 :(得分:0)
您可以简单地添加此代码。
<?php
function convertCurrency($amount, $from, $to){
$data = file_get_contents("https://www.google.com/finance/converter? a=$amount&from=$from&to=$to");
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted);
$converted = preg_replace("/[^0-9.]/", "", $converted[1]);
return number_format(round($converted, 3),2);
}
echo convertCurrency("10", "AED", "USD");
?>