2017-09-14 116 views
0

我在一行代碼在這裏得到一個錯誤:ErrorException:未定義抵消:1

$converted = preg_replace("/[^0-9.]/", "", $converted[1]); 

有誰知道是什麼原因引起的?

public function convertCurrency($amount, $from, $to) { 
$url = "https://www.google.com/finance/converter?a=$amount&from=$from&to=$to"; 
$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); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
$rawdata = curl_exec($ch); 
if ($rawdata === FALSE) { 
echo "cURL Error: " . curl_error($ch); 
} else { 
preg_match("/<span class=bld>(.*)<\/span>/", $rawdata, $converted); 
$converted = preg_replace("/[^0-9.]/", "", $converted[1]); 
return number_format(round($converted, 3), 2); 
} 
curl_close($ch); 
} 
+1

看起來像PHP代碼。這可能有助於獲得響應,然後添加php標籤([php])。 –

+0

可能重複[參考 - 這是什麼意思在PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Chris

+0

是它的PHP作爲在標題說AdminController.php theres超過1500行代碼,但在這裏停止在行1410 它有一個開放的PHP和密切的PHP標記 –

回答

0

該代碼是正確的。 谷歌現在在表單中有一個隱藏的輸入。 輸入是動態的,每次都會改變。 這是給錯誤。 感謝您關注此問題。