Hi friends

i am working for an shopping cart using php script, i placed a drop down option to display currency rate as per user selection(INR and USD). By default it will display all the price in INR, if any user select USD, then it has to show all the values in USD.I dont know how to display the USD live rates. can any one please help to resove the issue.

Re: convert INR to USD for shopping cart 80 80
Member Avatar

You could use a site like this - which has an API. I assume that you'll need an API of some description.

https://openexchangerates.org/

You could get a free account or depending on your traffic, pay something like $12/mo.

Re: convert INR to USD for shopping cart 80 80

Thanks diafol, i will check it

Re: convert INR to USD for shopping cart 80 80

You'll need to use an exchange rate API, then parse/decode the results. Google and Yahoo each have APIs (a quick search should turn up more info), and another resource I found is https://openexchangerates.org/

EDIT: Just saw diafol's response. Sorry, had this tab open for a while before I got to it.

Re: convert INR to USD for shopping cart 80 80

HI Friends

Thanks for your post, with help of your post i got an idea and i used the below free API code

<?php
        $from   = 'USD'; /*change it to your required currencies */
        $to     = 'INR';
        $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 $1 in Indian Rupees is &#x20B9; '.$dollarValue;
?>
Re: convert INR to USD for shopping cart 80 80

Thank You. Its Working, I have little change on it....

<?php

$_POST['amount']="35.00";
$_POST['from']="INR";
$_POST['to']="USD";

$amount = urlencode($_POST['amount']);
$from_Currency = urlencode($_POST['from']);
$to_Currency = urlencode($_POST['to']);

$url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from_Currency . $to_Currency .'=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]*$amount;
    echo  round($dollarValue , 2);
}
else{
    echo "ERROR";
}

?>
Re: convert INR to USD for shopping cart 80 80

I got error "It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com." after 2-3 weaks of using this code.
Please advice some another working yahoo api.

Re: convert INR to USD for shopping cart 80 80

Not working now ...... Yahoo shutdown this service.

If any other way to get value then please let me know.

Re: convert INR to USD for shopping cart 80 80

I googled that and found php examples out there for other API's. Example http://www.phpzag.com/convert-currency-using-google-api/

I know folk hate to do research but today, you can save a lot of time and get there faster with a little effort.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.