<?php


// function currencyConverter($from_Currency,$to_Currency,$amount) {
	
	
 // $from_Currency = urlencode($from_Currency);
 // $to_Currency = urlencode($to_Currency);
 // $encode_amount = 1;
 
// $get = file_get_contents("https://finance.google.com/bctzjpnsun/converter?a=$encode_amount&from=$from_Currency&to=$to_Currency");
// $get = explode("<span class=bld>",$get);
// $get = explode("</span>",$get[1]);
// $rate= preg_replace("/[^0-9\.]/", null, $get[0]);
// $converted_amount = $amount*1;
 // $data = array( 'rate' => $rate, 'converted_amount' =>$converted_amount, 'from_Currency' => strtoupper($from_Currency), 'to_Currency' => strtoupper($to_Currency));
// $return_json =  json_encode( $data );
// return $return_json;
// }

// $converted_currency=currencyConverter('USD', 'INR', '10');
// echo $converted_currency;




function currencyConverter($from_Currency,$to_Currency,$amount) {
	
	
 $from_Currency = urlencode($from_Currency);
 $to_Currency = urlencode($to_Currency);
 $encode_amount = 1;
 
 $url = "https://finance.google.com/bctzjpnsun/converter?a=$encode_amount&from=$from_Currency&to=$to_Currency"; 
 
 $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); 
 $response = explode("<span class=bld>",$response);
$response = explode("</span>",$response[1]);
$rate= preg_replace("/[^0-9\.]/", null, $response[0]);

$converted_amount = $amount*1;
 $data = array( 'rate' => $rate, 'converted_amount' =>strval(round($converted_amount, 2)), 'from_Currency' => strtoupper($from_Currency), 'to_Currency' => strtoupper($to_Currency));
$return_json =  json_encode( $data );
return $converted_amount;
}

$converted_currency=currencyConverter('USD', 'INR', 10);
echo $converted_currency;

?>

