Welcome to CodeGlobe. CodeGlobe provides free source code, tutorials and latest useful technology news.
Monday, June 8, 2009
Currency Exchange Rate from Europian Cental Bank (PHP)
// Define a context for HTTP.
$aContext = array(
'http' => array(
'proxy' => 'tcp://192.168.0.5:3128', // This needs to be the server and the port of the NTLM Authentication Proxy Server.
'request_fulluri' => True,
),
);
$cxContext = stream_context_create($aContext);
// Now all file stream functions can use this context.
//$sFile = file_get_contents("http://www.php.net", False, $cxContext);
//This is a PHP (4/5) script example on how eurofxref-daily.xml can be parsed
//Read eurofxref-daily.xml file in memory
$XMLContent= file("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",False,$cxContext);
//the file is updated daily between 2.15 p.m. and 3.00 p.m. CET
foreach ($XMLContent as $line) {
if (ereg("currency='([[:alpha:]]+)'",$line,$currencyCode)) {
if (ereg("rate='([[:graph:]]+)'",$line,$rate)) {
//Output the value of 1 EUR for a currency code
echo '1 € = '.$rate[1].' '.$currencyCode[1].'
';
//--------------------------------------------------
// Here you can add your code for inserting
// $rate[1] and $currencyCode[1] into your database
//--------------------------------------------------
}
}
}
?>
Labels:
PHP
Subscribe to:
Post Comments (Atom)
Good News Good Information good Article
ReplyDelete