Created
June 24, 2013 14:12
-
-
Save demux/5850341 to your computer and use it in GitHub Desktop.
Convert XML exchange rates from arionbanki.is to JSON or JSONP for money.js (http://josscrowcroft.github.io/money.js/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$xml_url = 'http://www.arionbanki.is/markadir/gjaldmidlar/gengi/xml-export'; | |
$data = simplexml_load_file($xml_url); | |
$out = array( | |
'timestamp' => time(), | |
'base' => 'ISK', | |
'rates' => array() | |
); | |
foreach($data->items->Currency as $cur) { | |
if(isset($_GET['tegund']) and $_GET['tegund'] === 'kaup') { | |
$gengi = (float)$cur->Kaupgengi; | |
} else { | |
$gengi = (float)$cur->Solugengi; | |
} | |
$mynt = (string)$cur->mynt; | |
$out['rates'][$mynt] = $gengi; | |
} | |
$json = json_encode($out); | |
if(!empty($_GET['callback'])) { | |
echo $_GET['callback'] . '(' . $json . ')'; | |
} else { | |
echo $json; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment