This article describes how to use the yahoo Exchange Rate Interface to implement real-time exchange rate conversion. For more information, see the following code:
The Code is as follows:
Function getExchangeRate ($ from_Currency, $ to_Currency)
{
$ Amount = urlencode ($ amount );
$ From_Currency = urlencode ($ from_Currency );
$ To_Currency = urlencode ($ to_Currency );
$ Url = "download.finance.yahoo.com/d/quotes.html? S = ". $ from_Currency. $ to_Currency." x&f;sl1d1t1ba&e;.html ";
$ Ch = curl_init ();
$ Timeout = 0;
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1 )");
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
$ Rawdata = curl_exec ($ ch );
Curl_close ($ ch );
$ Data = explode (',', $ rawdata );
Return $ data [1];
}
// Call Method
Echo getExchangeRate ("CNY", "USD ");