PHP Currency Converter (Google Version)


/ Published in: PHP
Save to your folder(s)

PHP Currency converter function that uses Google


Copy this code and paste it in your HTML
  1. function currency_convert($from,$to,$amount) {
  2. $string = "1".$from."=?".$to;
  3. $google_url = "http://www.google.com/ig/calculator?hl=en&q=".$string;
  4. $result = file_get_contents($google_url);
  5. $result = explode('"', $result);
  6. $converted_amount = explode(' ', $result[3]);
  7. $conversion = $converted_amount[0];
  8. $conversion = $conversion * $amount;
  9. $conversion = round($conversion, 2);
  10. $rhs_text = ucwords(str_replace($converted_amount[0],"",$result[3]));
  11. $rhs = $conversion.$rhs_text;
  12. $price = preg_replace('_^\D+|\D+$_', "", $rhs);
  13. return number_format($price, 2, '.', ',');
  14. }
  15. echo currency_convert('GBP', 'USD',800.00)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.