Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2. function convertCurrency($amount, $from, $to) {
  3. $url = 'http://finance.google.com/finance/converter?a=' . $amount . '&from=' . $from . '&to=' . $to;
  4. $data = file_get_contents($url);
  5. preg_match_all("/<span class=bld>(.*)<\/span>/", $data, $converted);
  6. $final = preg_replace("/[^0-9.]/", "", $converted[1][0]);
  7. return round($final, 3);
  8. }
  9.  
  10. echo convertCurrency(1, 'EUR', 'PLN'); // output: 1.195
  11.  
  12. echo convertCurrency(1, 'USD', 'PLN'); // output: 1.195
  13.  
  14. /* I got errors until i've changed this line:
  15. $final = preg_replace("/[^0-9.]/", "", $converted[1]); to:
  16. $final = preg_replace("/[^0-9.]/", "", $converted[1][0]);
  17. .. maybe it works for your code too
  18. */
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement