Home » Build Currency Converter in PHP with Google API

Build Currency Converter in PHP with Google API

Today, We want to share with you google currency converter api php.In this post we will show you free currency converter api php, hear for live currency converter in php we will give you demo and example for implement.In this post, we will learn about All Coins And Cryptocurrency Data API PHP, Ruby, Python with an example.

google currency converter api php

here in this Example You learn All About Example of currency converter in php source code, google finance converter api, currency converter api android with demo and full source code.

Read Also:  Laravel 6 String Explode and Implode Tutorial

Step 1: Creare Currency Convert HTML Form

<div class="container">
	<h2>Example: Build Currency Converter in PHP - www.pakainfo.com</h2>	
	<form method="post" id="money-convert-form">
		<div class="form-group row">
		 <div class="col-xs-4">
		<label for="from_curr">From:</label>
		<select name="money_from" class="form-control">
		<option value="INR">Indian Rupee</option>
		<option value="USD" selected="1">US Dollar</option>
		<div class="form-group row">
		<div class="col-xs-4">
		<label for="pwd">To:</label>
		<select name="money_to" class="form-control">
		<option value="INR" selected="1">Indian Rupee</option>
		<option value="USD">US Dollar</option>
		<div class="col-xs-4">
		<div id="money_conversion_rate"></div>	
		<div id="converted_money_amount"></div>		
		<div class="form-group row">
		<div class="col-xs-4">
		<label>Amount :</label>
		<input type="number" placeholder="amount" name="amount" id="amount" class="form-control">
		<button type="submit" class="btn btn-info" name="convert_money" id="convert_money">Convert</button>		

Step 2: Handle Currency Form Submit with Ajax

$('document').ready(function() {	
		rules: {
			amount: {
				required: true,
		messages: {
			  required: ""
		submitHandler: moneyConvertFormSubmit	
	function moneyConvertFormSubmit() {		
		var data = $("#money-convert-form").serialize();				
			type : 'POST',
			url  : 'convert_money.php',
			data : data,
			beforeSend: function(){					
			success : function(response){				
		return false;

Step 3: Convert currency into another currency with Google Currency API

if(isset($_POST['convert_money'])) {
	$money_from = trim($_POST['money_from']);
	$money_to = trim($_POST['money_to']);
	$amount = trim($_POST['amount']);	
	if($money_from == $money_to) {
	 	$data = array('error' => '1');
		echo json_encode( $data );	
	$converted_money=convertCurrency($money_from, $money_to, $amount);
	echo $converted_money;

Step 4: Create currency convert function

function convertCurrency($money_from,$money_to,$convert_amount) {	
	$money_from = urlencode($money_from);
	$money_to = urlencode($money_to);	
	$moneyUrl = "https://www.google.com/search?q=".$money_from."+to+".$money_to;
	$moneyDetails = file_get_contents($moneyUrl);
	$moneyData = preg_split('/\D\s(.*?)\s=\s/',$moneyDetails);
	$conversion_rate = (float) substr($moneyData[1],0,7);	
	$total_converted_money_amount = $convert_amount*$conversion_rate;
	$moneyJsonData = array( 'rate' => $conversion_rate, 'total_converted_money_amount' =>$total_converted_money_amount, 'money_from' => strtoupper($money_from), 'money_to' => strtoupper($money_to));
	echo json_encode( $moneyJsonData );	

I hope you get an idea about google currency converter api javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Retrieve last insert id by Eloquent in Laravel 6

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Multiple file Upload in Laravel 5.7 with validation
  2. Read Also:  left outer join vs left join
  3. Read Also:  PHP Fetch all HTTP request headers
  4. Read Also:  Laravel 5.7 Datatables Tutorial With Example
  5. Read Also:  PHP Remove File from Folder and Database
  6. Read Also:  SKT IT Consultant Wordpress theme By SKT Themes
  7. Read Also:  Angular 9/8 SEO Dynamic Rendering Title and Meta Tags
  8. Read Also:  Simple Vue.js Form Validation Example
  9. Read Also:  Laravel 6 String Explode and Implode Tutorial
  10. Read Also:  Laravel 5.7 Datatables Tutorial With Example

Leave a Comment

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