Page 1 of 1

How to convert INR to Dollar???

Posted: Tue May 04, 2010 2:58 am
by amitdubey2
Hello all,

I am working on a project where i need to implement a code which can change INR(Indian Rupees) to USD (Dollar).Currently i got a code from net but i am nt able to get the correct exchange rate....i don't knw the problem and need help ...below i am attaching the code please check this

Code: Select all

<?php
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]);
unset ($buffer);
return $match[0][0];
}
?>
<?php

echo currency_convert(200,"USD","INR");
?>


Thanks
Amit

Re: How to convert INR to Dollar???

Posted: Tue May 04, 2010 6:50 am
by maneetpuri
Hi,

I saw the code, I think the problem is with some value that you are passing to the yahoo API for doing this conversion, you will have to refer to the user guide of the same so that you know the purpose of various variables passed and the correct values for them.

Cheers,

~Maneet

Re: How to convert INR to Dollar???

Posted: Tue May 04, 2010 11:49 pm
by amitdubey2
hello maneetpuri,

i have checked the url before and it is passing variables (from, to, and amt) and in the above script i think same are passing...i dont knw where the problem is exactly.
i think some problem is in storing it in buffer so variables are nt going to yahoo API or somthing else...
if you can tell exactly where to make change then it will be appriciable... :D





Thanks
amit