Currency convert using Google and Yahoo services in Php

In Php programming, Convert Amount from one currency to another currency is very easy using Google & Yahoo Finance services. even you can direct convert using Google Currency Converter and Yahoo Currency Converter


Currency convert Using Google Finance in Php

<?php

$get = file_get_contents("https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency");
$get = explode("",$get);
$get = explode("",$get[1]);  
$rawdata = preg_replace("/[^0-9\.]/", null, $get[0]);
$to_amount = $rawdata;
return $to_amount;

?>			

Currency Convert using YAHOOO Finance in Php

<?php
function convert_currencyi($from, $to)
{
  $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); 
  $dollarValue = $allData[1];
        
  return $dollarValue;
        
  //return number_format($dollarValue, 2, '.', '');
}
?>

Post a Comment

0 Comments