Created
March 21, 2018 06:59
-
-
Save bllohar/d3af15a452e7b73722ec59123b32d805 to your computer and use it in GitHub Desktop.
Get INR converted to USD using google query and parsing + curl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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