Saturday, 2 August 2014

CURRENCY

<?php

function currency($from_Currency, $to_Currency, $amount) {
  $amount = urlencode($amount);
  $from_Currency = urlencode($from_Currency);
  $to_Currency = urlencode($to_Currency);
  $url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
  $ch = curl_init();
  $timeout = 0;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $rawdata = curl_exec($ch);
  curl_close($ch);
  $data = explode('"', $rawdata);
  $data = explode(' ', $data['3']);
  $var = $data['0'];
  return round($var, 3);
}

echo currency(USD, PKR, 1) . "<br />"; // echo 973.236 // http://www.google.com/ig/calculator?hl=en&q=PKR=?1USD
echo currency(USD, PKR, 10) . "<br />"; // echo 972.478849 // http://www.google.com/ig/calculator?hl=en&q=PKR=?10USD
echo currency(USD, PKR, 11); // echo 11 but it should return 1 069.72673 // http://www.google.com/ig/calculator?hl=en&q=PKR=?11USD
?>

No comments:

Post a Comment