Guest User

Currency Converter from google free of cost

a guest
Oct 24th, 2018
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. public function convertCurrency()
  2.     {
  3.         $amounts = 597;
  4.         $from_currency='USD';
  5.         $to_currency='INR';
  6.         $url = 'https://www.google.co.za/search?q='.$amounts.'+' . $from_currency . '+to+' . $to_currency;
  7.  
  8.         $cSession = curl_init();
  9.  
  10.         curl_setopt($cSession, CURLOPT_URL, $url);
  11.         curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
  12.         curl_setopt($cSession, CURLOPT_SSL_VERIFYPEER, true);
  13.  
  14.         $buffer = curl_exec($cSession);
  15.         curl_close($cSession);
  16.  
  17.         preg_match("/<div class=\"J7UKTe\">(.*)<\/div>/",$buffer, $matches);
  18.         $matches = preg_replace("/[^0-9.]/", "", $matches[1]);
  19.         $amount =  round($matches, 2);
  20.         $total = substr($amount, mb_strlen($amounts));
  21.         return number_format($total,2);
  22.     }
Add Comment
Please, Sign In to add comment