Hi Guys
I'm back...greetings to all and thanks for keeping in touch.
Not sure even where to post this question but php section usually is cool.
Is there any guru here willing to help me make a display of exchange rates on my site? I only need Euro, Sterling, USD and BG lev.
Regards
F

Welcome back (I don't know you though). Could you explain what exactly are you looking for ?

I would suggest using curl to tap into another websites currency converter. Let me know if you would like an example as it would be kinda hard to make.

I would suggest using curl to tap into another websites currency converter. Let me know if you would like an example as it would be kinda hard to make.

I would surely love to see one..

Hi Guys
I'm back...greetings to all and thanks for keeping in touch.
Not sure even where to post this question but php section usually is cool.
Is there any guru here willing to help me make a display of exchange rates on my site? I only need Euro, Sterling, USD and BG lev.
Regards
F

Hi
So far I have this

<?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 14:15 and 15:00 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 &euro; = '.$rate[1].' '.$currencyCode[1].'<br />';
                    //--------------------------------------------------
                    // Here you can add your code for inserting
                    // $rate[1] and $currencyCode[1] into your database
                    //--------------------------------------------------
            }
        }
}
?>

but want to make it much better. I guess could now throw into a database and extract whatever is required, even to make one of those on-line calculators.
Best
F

Hi again
here is the code that I have so far but can't get it insert data into my database. Any help would be appreciated.
best
F

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

<?php
require("./resources/globals.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 14:15 and 15:00 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 &euro; = '.$rate[1].' '.$currencyCode[1].'<br />';
					
	$rate=$rate[1];
	$currencyCode=$currencyCode[1];
	$updateStmt = "Update currency SET rate=$rate  WHERE code = $currencyCode ";
	

// Connect to the Database
if (!($link=mysql_pconnect($location,$userName,$password))) {
   DisplayErrMsg(sprintf("error connecting to host %s, by user %s",
                             $location, $userName)) ;
   //exit() ;
}

// Select the Database
if (!mysql_select_db($dbname, $link)) {
   DisplayErrMsg(sprintf("Error in selecting %s database", $dbname)) ;
   DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link))) ;
   //exit() ;
}

// Execute the Statement
if (!mysql_query ($updateStmt)){
echo $updateStmt;
// Execute the Statement
//if (!mysql_query($updateStmt, $link)) {
   DisplayErrMsg(sprintf("Error in executing %s stmt", $updateStmt)) ;
   DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link))) ;
   //exit() ;
}

}
echo $updateStmt; ///displays only one record and no database insert
			}
		
}

?> 

</body>
</html>

I would surely love to see one..

Well here is a function:

function currency_convert($Amount,$currencyfrom,$currencyto)
{
$buffer=file_get_contents('http://finance.yahoo.com/currency-converter');
preg_match_all('/name=(\"|\')conversion-date(\"|\') value=(\"|\')(.*)(\"|\')>/i',$buffer,$match);
$date=preg_replace('/name=(\"|\')conversion-date(\"|\') value=(\"|\')(.*)(\"|\')>/i','$4',$match[0][0]);
unset($buffer);
unset($match);
$buffer=file_get_contents('http://finance.yahoo.com/currency/converter-results/'.$date.'/'.$Amount.'-'.strtolower($currencyfrom).'-to-'.strtolower($currencyto).'.html');
preg_match_all('/<span class=\"converted-result\">(.*)<\/span>/i',$buffer,$match);
$match[0]=preg_replace('/<span class=\"converted-result\">(.*)<\/span>/i','$1',$match[0]);
//return $buffer;
unset ($buffer);
return $match[0][0];
}
//Theory: currency_convert(Amount,From,To)
echo currency_convert(150.5,'GBP','AUD');

And the possible entries that can be entered into the from and to field are as follows:

-------------
CONVERT FROM:
-------------

British Pound         GBP
Euro                  EUR
US Dollar             USD
Japanese Yen          JPY
Chinese Yuan          CNY
Australian Dollar     AUD
Swiss Franc           CHF
Canadian Dollar       CAD
Thai Baht             THB
Indian Rupee          INR
Indonesian Rupiah     IDR
Hong Kong Dollar      HKD

-----------
CONVERT TO:
-----------

Euro                  EUR
British Pound         GBP
US Dollar             USD
Japanese Yen          JPY
Chinese Yuan          CNY
Australian Dollar     AUD
Swiss Franc           CHF
Canadian Dollar       CAD
Thai Baht             THB
Indian Rupee          INR
Indonesian Rupiah     IDR
Hong Kong Dollar      HKD

As you can see all the names have abbreviations. For this script, you need to use these abbreviations to be able to convert currencies. And in case if you are wondering how it works, it uses the yahoo currency converter which as far as I am aware hasn't clearly stated anying that could cause legal problems with this script. And also note it takes about 3 seconds to process this function.

Cool thanks, I'll have a look see and try to get it to work.
Best
F

This site allows you to add currency exchange rates table to your site. You can add any pair of currencies to the table.

<website snipped>

Edited 6 Years Ago by nav33n: URL snipped. Do not spam, advertise, plug your website, or engage in any other type of self promotion.

This article has been dead for over six months. Start a new discussion instead.