Home

Friday, May 30, 2014

Currency Converter In PHP

/*British Pound GBP
Euro EUR
US Dollar USD
Japanese Yen JPY
Chinese Yuan CNY
Australian Dollar AUD
Swiss Franc CHF
Canadian Dollar CAD
Thai Baht THB
Indian Rupee INR
Indonesian Rupiah IDR
Hong Kong Dollar HKD*/


    $from_Currency = "USD";
    $to_Currency = "EUR";
    $amount = 1;

    $amount = urlencode($amount);
    $from_Currency = urlencode($from_Currency);
    $to_Currency = urlencode($to_Currency);
    $get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
    $get = explode("<span class=bld>",$get);
    $get = explode("</span>",$get[1]); 
    $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);
   
    $formatter = new NumberFormatter('en_EN',  NumberFormatter::CURRENCY);
    echo "=>  ".$formatter->formatCurrency($converted_amount, 'EUR') . PHP_EOL;

No comments:

Post a Comment

rathoddhirendra.blogspot.com-Google pagerank and Worth