0
我正在尋找一種貨幣轉換器用PHP編寫的用戶輸入,所以用戶可以輸入一個值,然後輸出它。這是主要劇本。貨幣轉換器(用戶輸入)
<?php
$from_currency = 'EUR';
$to_currency = 'USD';
$amount = 1;
$results = converCurrency($from_currency,$to_currency,$amount);
$regularExpression = '#\<span class=bld\>(.+?)\<\/span\>#s';
preg_match($regularExpression, $results, $finalData);
echo $finalData[0];
function converCurrency($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;
}
?>
我必須添加到這個腳本,用戶可以把他自己的價值。
使用'$ _GET'或'$ _POST'。另外,確保你驗證你的輸入。 – Halcyon
似乎有相當多的apis在互聯網上提供貨幣轉換並以比手動解析Google結果更可用的格式返回數據 – RamRaider
ie:http://jsonrates.com/? – RamRaider