Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Php: How to convert currency using Google Finance ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 315
    Comment on it

    In this blog I am going to tell you how to convert currency using Google Finance. Example: you want to convert Indian Rupee to American Dollar i.e. INR to USD then you can convert it using following url: http://www.google.com/finance/converter?a=$amount&from=$from&to=$to

    Pass following: $amount=100 , $from = INR,  $to= USD

    url will look like: http://www.google.com/finance/converter?a=100&from=INR&to=USD.

    Lets implement it:

    Create php file convert_currency.php

    function currencyConvert($from,$to,$amount){
     
        $url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
     
        $request = curl_init();
        $timeOut = 0;
        curl_setopt ($request, CURLOPT_URL, $url);
        curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);
     
        curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
        curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);
        $response = curl_exec($request);
        curl_close($request);
     
        return $response;
    } 

    This function accept 3 parameters and send request to Google finance using HTTP and it will return complete code. Now you can call this function where you needed it.

    Thanks for reading the blog.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: