Skip to main content

Currency conversion in PHP Using Google API

Most of us use Google for searching web information. Google also provides Currency Converter API for converting currency to our desired currency. We can see the current status of our currency into other currency by going through Google’s currency converter page. However, sometimes we need to implement Google currency converter functionality on our application. This is very simple; you can implement it very easily with Google currency convert API using PHP.

Here in this tutorial, you will learn how to implement currency conversion functionality using PHP with demo.

Below is complete PHP currency converter script using Google API which have a function currencyConverter($from_Currency,$to_Currency,$amount) with three parameters. The first parameter is $from_Currency, the second is $to_Currency means the currency in which it is converted. And third parameter is $amount that will be passed for conversion.

PHP currency convert  functions:
function currencyConverter($from_Currency,$to_Currency,$amount) {
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$get = file_get_contents("$from_Currency&to=$to_Currency");
$get = explode("<span class=bld>",$get);
$get = explode("</span>",$get[1]);
$converted_currency = preg_replace("/[^0-9\.]/", null, $get[0]);
return $converted_currency;

PHP currency convert  function call:
// change amount according to your needs
$amount =10;
// change From Currency according to your needs
$from_Curr =“INR”;
// change To Currency according to your needs
$to_Curr =“USD”;
$converted_currency=currencyConverter($from_Curr, $to_Curr, $amount);
// Print outout
echo $converted_currency;

You can view the live demo from the Demo link and can download the script from the Download link below.


11 thoughts on “Currency conversion in PHP Using Google API

  1. Sorry Typos. Should have been:

    Looks like Google made a change because my script (similar to yours) stopped working as has yours. Just did your demo and keep getting “No Result”.

    They have added a dynamically generated variable named “meta”. I have been trying to code for this, but no luck so far. Any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *


Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!