/    Sign up×
Community /Pin to ProfileBookmark

currency conversion

Is there a way of checking and displaying the currency conversion for price using php?
I want to connect to the database get the price in one currency and then check the rate and display the second curreny.

thanks

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@MrCoderMar 21.2007 — Oanda (http://www.oanda.com)

XE (http://www.xe.com)

These 2 sites offer live exchange rates, maybe they have an API?
Copy linkTweet thisAlerts:
@NightShift58Mar 22.2007 — Or these guys:

http://finance.yahoo.com/

If you Google it, you'll find tons of scripts to scrape from Yahoo
Copy linkTweet thisAlerts:
@bunny1authorMar 22.2007 — i got this script that uses yahoo

[code=php]<?php
$price = '100';
$ticker= 'USDEUR=X';
$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$ticker&f=sl1d1t1c1ohgv&e=.csv", "r");
$exchange_rate = fread($open, 2000);
fclose($open);
$exchange_rate = str_replace(""", "", $exchange_rate);
$exchange_rate = explode(",", $exchange_rate);
$ca_price = ($us_price/$exchange_rate[1]);
$price = number_format ($ca_price, 2);

echo "$price Euro = $$price US dollars";
?> [/code]


when i upload the pg and try to open it, it takes ages and then i get "page cannot be displayed". I take it that it's slow because it must go to the yahoo page.

Is this a problem with my host. And how can i fix this.

Thank you
Copy linkTweet thisAlerts:
@NightShift58Mar 22.2007 — Take a look at this page, where Yahoo is used and it's pretty fast.

http://www.costaricalaw.com/LEGALNET/real_estate_law/closecost.php
Copy linkTweet thisAlerts:
@NightShift58Mar 22.2007 — Code used in previous example:[code=php]<?php
//Get the exchange rate from Yahoo
$thisRATE = file_get_contents("http://finance.yahoo.com/d/quotes.csv?s=USDCRC=X&f=sl1d1t1ba&e=.csv");
if ($thisRATE === FALSE) :
$EXCHrate = 520;
$EXCHinfo = "Based on <b>$1.00</b> = <b>¢520.00</b>";
else :
$arrRATE = split(",", $thisRATE);
$EXCHrate = $arrRATE[5];
$EXCHdata = str_replace('"', "", $arrRATE[2] . " at " . $arrRATE[3]);
$EXCHinfo = "Based on <b>$1.00</b> = <b>¢$EXCHrate</b> on $EXCHdata";
if ($EXCHrate < 490 or $EXCHrate > 600) :
$EXCHrate = 520;
$EXCHinfo = "Based on <b>$1.00</b> = <b>¢520.00</b>";
endif;
endif;
?>[/code]
Copy linkTweet thisAlerts:
@bunny1authorMar 22.2007 — thanks that works great!
×

Success!

Help @bunny1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...