0

I'm using Google Finance API and when I ever click on convert in my form I get this error :

<br /> <b>Warning</b>: file_get_contents(https://finance.google.com/finance/converter?a=SDG&amp;from=CAD&amp;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;
}
?>

I tried to use urlencode() to the URL but it's not working.

I read curl is the better case but don't want to use curl.

any idea how I can make it work?

Alan
  • 386
  • 1
  • 3
  • 17
  • 1
    The API is returning a 503, because it is apparently deprecated. See [**this answer**](https://stackoverflow.com/a/22809073/2341603). – Obsidian Age Feb 19 '18 at 02:49
  • it's possible you don't have the right PHP configuration for fetching a `https://` link https://stackoverflow.com/questions/1975461/how-to-get-file-get-contents-to-work-with-https – Scuzzy Feb 19 '18 at 02:51
  • @ObsidianAge the answer is not helping – Alan Feb 19 '18 at 03:21
  • How does it not help? It states that the API is deprecated, and even offers [**an alternative**](http://scrape-google-finance.compunect.com/), written in PHP no less. – Obsidian Age Feb 19 '18 at 03:27

0 Answers0