-
-
Save dcblogdev/8067095 to your computer and use it in GitHub Desktop.
<?php | |
function convertCurrency($amount, $from, $to){ | |
$data = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from&to=$to"); | |
preg_match("/<span class=bld>(.*)<\/span>/",$data, $converted); | |
$converted = preg_replace("/[^0-9.]/", "", $converted[1]); | |
return number_format(round($converted, 3),2); | |
} | |
echo convertCurrency("10.00", "GBP", "USD"); |
It is not the best solution and not very clean, but you can do this:
- Convert from your old currency to BTC (Bitcoin)
- Convert your Bitcoin to your new currency! ;-)
Example for 100 EUR to USD:
-
100 EUR to Bitcoin. Result: 0.01282849
https://blockchain.info/tobtc?currency=EUR&value=100 -
Convert 01282849 (without "0.") to USD
https://blockchain.info/frombtc?value=01282849¤cy=USD
Attention: In this solution you can convert max 1 full Bitcoin (~8000 EUR)
PHP Code:
function convert($amount, $from, $to)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://blockchain.info/tobtc?currency=" . $from . "&value=" . $amount);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$conversion = curl_exec($ch);
$conversion = substr($conversion, 2);
curl_setopt($ch, CURLOPT_URL, "https://blockchain.info/frombtc?currency=" . $to . "&value=" . $conversion);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return $conversion = curl_exec($ch);
}
echo convert(100, "EUR", "USD");
Here we are again :(
Any solutions!!