2

Possible Duplicate:
Programmatically access currency exchange rates

Is there any api which provide exact converted value of currency? I have used google and yahoo api but they are not giving required result for VND(Vietnamese dong) to US dollars.

Community
  • 1
  • 1
somu.web
  • 379
  • 1
  • 5
  • 14

1 Answers1

2

How's this ?

<?php

$amount = urlencode("1");
$from_Currency = urlencode("VND");
$to_Currency = urlencode("USD");
$url = "hl=en&q=$amount$from_Currency%3D%3F$to_Currency";
$rawdata = file_get_contents("http://google.com/ig/calculator?".$url);
$data = explode('"', $rawdata);
$data = explode(' ', $data['3']);
$var = $data['0'];
echo $var;

?>
Joel Murphy
  • 2,472
  • 3
  • 29
  • 47
  • am using this only but it is returning the result as 4.8 but the actual value is 0.00004 it is not giving 10pow-5 – somu.web Nov 30 '11 at 11:51
  • i have also tried this --- $from = 'VND'; $to = 'USD'; $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X'; $handle = @fopen($url, 'r'); if ($handle) { $result = fgets($handle, 4096); fclose($handle); } $allData = explode(',',$result); /* Get all the contents to an array */ $dollarValue = $allData[1]; echo 'Value of 1VND in USD is $. '.$dollarValue; -- it giving the ouput as 0.00 – somu.web Nov 30 '11 at 12:14
  • Hmm. If you just echo out $rawdata and remove the rest of the code, you will get this output: {lhs: "1 Vietnamese dong",rhs: "4.8 \x26#215; 10\x3csup\x3e-5\x3c/sup\x3e U.S. dollars",error: "",icc: true} - Maybe you could try stripping this down using a regular expression or just use PHP's explode method to get the output you need? – Joel Murphy Nov 30 '11 at 13:25
  • The value will be in the format of 4.8e-5 but I need it as 0.000048. I couldn't able to convert that. – somu.web Nov 30 '11 at 13:45