Currency Converter Help Of Yahoo API

Some time you need to convert currency into another currency like USD to EUR, Ruppe to USD. so, you can done this by yahoo API yes yahoo provide to programmer to open source API for any currency convert to another currency


Simple make one function and write following code in your function.




function convertUSD($USD, $EUR)
{
$xml = file_get_contents('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDEUR%22,%20%22USDJPY%22,%20%22USDBGN%22,%20%22USDCZK%22,%20%22USDDKK%22,%20%22USDGBP%22,%20%22USDHUF%22,%20%22USDLTL%22,%20%22USDLVL%22,%20%22USDPLN%22,%20%22USDRON%22,%20%22USDSEK%22,%20%22USDCHF%22,%20%22USDNOK%22,%20%22USDHRK%22,%20%22USDRUB%22,%20%22USDTRY%22,%20%22USDAUD%22,%20%22USDBRL%22,%20%22USDCAD%22,%20%22USDCNY%22,%20%22USDHKD%22,%20%22USDIDR%22,%20%22USDILS%22,%20%22USDINR%22,%20%22USDKRW%22,%20%22USDMXN%22,%20%22USDMYR%22,%20%22USDNZD%22,%20%22USDPHP%22,%20%22USDSGD%22,%20%22USDTHB%22,%20%22USDZAR%22,%20%22USDISK%22)&env=store://datatables.org/alltableswithkeys');

$data = simplexml_load_string($xml);

$data = json_encode($data->results->rate[0]->Rate);

$data = json_decode($data, true);

return number_format(($EUR*1)/$data[0], 2);
}


Source : laravelcode

Post a Comment

Post a Comment (0)

Previous Post Next Post