Skip to content

Instantly share code, notes, and snippets.

@demux
Created June 24, 2013 14:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demux/5850341 to your computer and use it in GitHub Desktop.
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/)
<?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