Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

FoxyShop Currency Converter Ajax Endpoint

sparkweb Feb 1st, 2012 254 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. <?php
  2. //Get Posted data
  3. $amount = $_POST['amount'];
  4. $from = $_POST['from'];
  5. $to = $_POST['to'];
  6.  
  7. //make string to be put in API
  8. $string = "1".$from."=?".$to;
  9.  
  10. //Call Google API
  11. $google_url = "http://www.google.com/ig/calculator?hl=en&q=".$string;
  12.  
  13. //Get and Store API results into a variable
  14. $result = file_get_contents($google_url);
  15.  
  16. //Explode result to convert into an array
  17. $result = explode('"', $result);
  18.  
  19. ################################
  20. # Right Hand Side
  21. ################################
  22. $converted_amount = explode(' ', $result[3]);
  23. $conversion = $converted_amount[0];
  24. //$conversion = preg_replace('/[x00-x08x0B-x1F]/', '', $conversion);
  25. $conversion = $conversion * $amount;
  26. $conversion = round($conversion, 2);
  27.  
  28. //Get text for converted currency
  29. $rhs_text = ucwords(str_replace($converted_amount[0],"",$result[3]));
  30.  
  31. //Make right hand side string
  32. $rhs = $conversion.$rhs_text;
  33.  
  34. ################################
  35. # Left Hand Side
  36. ################################
  37. $google_lhs = explode(' ', $result[1]);
  38. $from_amount = $google_lhs[0];
  39.  
  40. //Get text for converted from currency
  41. $from_text = ucwords(str_replace($from_amount,"",$result[1]));
  42.  
  43. //Make left hand side string
  44. $lhs = $amount." ".$from_text;
  45.  
  46. ################################
  47. # Make the result
  48. ################################
  49.  
  50. echo $lhs." = ".$rhs;
  51. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top