Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/04/2010, 11:08
Ember
 
Fecha de Ingreso: diciembre-2004
Ubicación: Madrid
Mensajes: 550
Antigüedad: 19 años, 3 meses
Puntos: 28
Respuesta: Conversor de monedas automático

muchas gracias Death_Empire, eso es lo que necesitaba, aunque he sustituido el file por el cURL porque me daba problemas para acceder al contenido del fichero XML

Código PHP:
<?php
//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");
//the file is updated daily between 2.15 p.m. and 3.00 p.m. CET
$ch curl_init();
$timeout 5// set to zero for no timeout
curl_setopt ($chCURLOPT_URL'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
curl_setopt ($chCURLOPT_CONNECTTIMEOUT$timeout);
$file_contents curl_exec($ch);
curl_close($ch);
$lines = array();
$lines explode("\n"$file_contents);

// display file line by line
foreach ($lines 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 &euro; = '.$rate[1].' '.$currencyCode[1].'<br />';
                    
//--------------------------------------------------
                    // Here you can add your code for inserting
                    // $rate[1] and $currencyCode[1] into your database
                    //--------------------------------------------------
            
}
        }
}
?>