Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

function quote_oanda_currency improvement


reffael

Recommended Posts

Posted

can i offer an improvement to the function, i think it's faster to use the oanda protocol instead of getting an html file and look for patterns in it. well those are my 2 cents :)

have a good day.

 

function quote_oanda_currency($code,$base=DEFAULT_CURRENCY) {

$err_num=$err_msg="";

$s=fsockopen("www.oanda.com", 5011, &$err_num, &$err_msg, 3);

if (!$s) {

echo "$err_msg ($err_num)<br>\n";

$resp="";

}

else {

fputs($s,"fxp/1.1\r\nbasecurrency: $base\r\nquotecurrency: $code\r\n\r\n");

$resp=fgets($s,128);

if (trim($resp)=="fxp/1.1 200 ok") {

while ($resp!="\r\n") {

$resp=fgets($s,128);

}

if(!$resp=fgets($s,128)) {

// timeout? then skip

$resp="";

}

print "$resp\n";

}

else {

$resp="";

}

}

fclose($s);

return trim($resp);

}

 

the current version of this function :

 

function quote_oanda_currency($code, $base = DEFAULT_CURRENCY) {

$page = file('http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch=' . $code . '&format=CSV&dest=Get+Table&sel_list=' . $base);

 

$match = array();

 

preg_match('/(.+),(\w{3}),([0-9.]+),([0-9.]+)/i', implode('', $page), $match);

 

if (sizeof($match) > 0) {

return $match[3];

} else {

return false;

}

}

 

what do u think? i haven't look at the xe service but maybe they have their own protocol.

Posted

well it's a shame if now they are taking money for this service, i took this function from an article published in 2001, and there is no reference to a payment for the service.

 

the article (from zend web site):

http://www.zend.com/zend/tut/currency-exchange.php

 

at least osC is still free :)

 

yap, after checking they want money, even a lot of money

"How to Subscribe to FXP?

FXP is available for $1,000 USD/month. On-line subscription for FXP is available. "

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...