我正嘗試使用Google API和PHP curl轉換貨幣數據。不幸的是我有以下問題,我仍然無法解決它。任何人都可以幫助我。 這裏是我的PHP函數。使用Google和CURL進行貨幣轉換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,2);
}
//這裏是我的函數調用
$usd= currency("USD","ETB",1);
echo "270 USD= ".$usd."ETB";
,但我遇到的follwing錯誤
注意:未定義抵消:3 ...上線...(14此功能)
'var_dump($ rawdata)'看看你實際得到了什麼。 – Passerby 2014-11-23 07:33:44
Igoogle已關閉並且您的網址結構也不正確 – 2014-11-23 07:36:44
@ Passerby,它會重蹈覆轍!這是什麼意思 – Mehari 2014-11-23 07:41:51