Skip to content

Instantly share code, notes, and snippets.

@deeprajsinha
Created October 24, 2018 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeprajsinha/f9a0dc137a8a96deeea84cd505686bc2 to your computer and use it in GitHub Desktop.
Save deeprajsinha/f9a0dc137a8a96deeea84cd505686bc2 to your computer and use it in GitHub Desktop.
Currency Conversion by google
public function convertCurrency()
{
$amounts = 597;
$from_currency='USD';
$to_currency='INR';
$url = 'https://www.google.co.za/search?q='.$amounts.'+' . $from_currency . '+to+' . $to_currency;
$cSession = curl_init();
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, true);
$buffer = curl_exec($cSession);
curl_close($cSession);
preg_match("/<div class=\"J7UKTe\">(.*)<\/div>/",$buffer, $matches);
$matches = preg_replace("/[^0-9.]/", "", $matches[1]);
$amount = round($matches, 2);
$total = substr($amount, mb_strlen($amounts));
return number_format($total,2);
}
or go to this link .. https://pastebin.com/TFewge8t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment