我使用Google财经API,当我点击表单中的转换时出现此错误:
<br /> <b>Warning</b>: file_get_contents(https://finance.google.com/finance/converter?a=SDG&from=CAD&to=+1): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
in <b>convert_api.php</b> on line <b>12</b><br /> <br /> <b>Notice</b>: Undefined offset: 1 in <b>\convert_api.php</b> on line <b>14</b><br /> <br /> <b>Notice</b>: Undefined offset: 1 in <b>C:\xampp\htdocs\c\convert_api.php</b> on line <b>15</b><br />
convert_api.php
<?php
$params = $_REQUEST;
//print_R($params);die('fff');
if(isset($params) && isset($params['amount']) && isset($params['from']) && isset($params['from'])) {
currencyConverter($params['from'], $params['to'], $params['amount']);
}
function currencyConverter($amount,$from_currency,$to_currency) {
$amount = urlencode($amount);
$from_currency = urlencode($from_currency);
$to_currency = urlencode($to_currency);
$get = file_get_contents("https://finance.google.com/finance/converter?a=$amount&from=$from_currency&to=$to_currency");
$get = explode("<span class=bld>",$get);
$get = explode("</span>",$get[1]);
$converted_currency = preg_replace("/[^0-9\.]/", null, $get[1]);
echo $converted_currency;
}
?>
我尝试将urlencode()用于网址,但它无效。
我读过curl是更好的情况但不想使用curl。
我知道如何让它发挥作用?