Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function convertCurrency($amount, $from, $to) {
- $url = 'http://finance.google.com/finance/converter?a=' . $amount . '&from=' . $from . '&to=' . $to;
- $data = file_get_contents($url);
- preg_match_all("/<span class=bld>(.*)<\/span>/", $data, $converted);
- $final = preg_replace("/[^0-9.]/", "", $converted[1][0]);
- return round($final, 3);
- }
- echo convertCurrency(1, 'EUR', 'PLN'); // output: 1.195
- echo convertCurrency(1, 'USD', 'PLN'); // output: 1.195
- /* I got errors until i've changed this line:
- $final = preg_replace("/[^0-9.]/", "", $converted[1]); to:
- $final = preg_replace("/[^0-9.]/", "", $converted[1][0]);
- .. maybe it works for your code too
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement