Posted By

digitalclubb on 02/03/12


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Net-Freak


PHP Currency Converter (Google Version)


 / Published in: PHP
 

PHP Currency converter function that uses Google

  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  

You need to login to post a comment.