Skip to content

Instantly share code, notes, and snippets.

@bllohar
Created March 21, 2018 06:59
Show Gist options
  • Save bllohar/d3af15a452e7b73722ec59123b32d805 to your computer and use it in GitHub Desktop.
Save bllohar/d3af15a452e7b73722ec59123b32d805 to your computer and use it in GitHub Desktop.
Get INR converted to USD using google query and parsing + curl
function getUSD($amount){
$url = "https://www.google.com/search?q=usd+to+inr";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$data = explode("1 US Dollar = ",$result);
$OneUSD = (float) substr($data[1],0,10);
return number_format($amount/$OneUSD,2);
}
// Usages
echo getUSD(100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment