public function convert() { function converCurrency($from, $to, $amount) { $url = "http://www.google.com/finance/converter?a={$amount}&from={$from}&to={$to}"; $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); return $response; } $from_currency = 'RUB'; $to_currency = 'PLN'; $amount = $this->request->param('convertFromValue'); $results = converCurrency($from_currency, $to_currency, $amount); $regularExpression = '#\\<span class=bld\\>(.+?)\\<\\/span\\>#s'; preg_match($regularExpression, $results, $finalData); $this->set('result', $amount . ' RUB = ' . $finalData[0]); //disable layout, we want only pure text $this->layout = false; }
public function createCurrency() { function converCurrency($from, $to, $amount) { $url = "http://www.google.com/finance/converter?a={$amount}&from={$from}&to={$to}"; $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); return $response; } $from_currency = 'USD'; $to_currency = $_POST['currency']; $amount = 1; $results = converCurrency($from_currency, $to_currency, $amount); $regularExpression = '#\\<span class=bld\\>(.+?)\\<\\/span\\>#s'; preg_match($regularExpression, $results, $finalData); $finalData[1]; $str = $finalData[1]; $rr = explode(" ", $str); Session::put('currency', $rr[1]); Session::put('currency_rate', $rr[0]); return Response::json(true); }
function currency_converter($convertable_amount, $convert_currency_from) { /* author: angshuman baruah subject : currency_converter - stage 1 year : 2016 */ $to_crncy_geo = currency_code(); $from_currency = $convert_currency_from; // as per php get $to_currency = $to_crncy_geo; $amount = $convertable_amount; $results = converCurrency($from_currency, $to_currency, $amount); $regularExpression = '#\\<span class=bld\\>(.+?)\\<\\/span\\>#s'; preg_match($regularExpression, $results, $finalData); $pre_final_x = $finalData[0]; $pre_final = str_replace($to_currency, "", $pre_final_x); $before_final = str_replace(" ", "", $pre_final); return $before_final; }
<!DOCTYPE html> <html> <head> <title>Currency Convertion.</title> </head> <body> <?php $from_currency = 'USD'; $to_currency = 'NPR'; $amount = 1; $results = converCurrency($from_currency, $to_currency, $amount); $regularExpression = '#\\<span class=bld\\>(.+?)\\<\\/span\\>#s'; preg_match($regularExpression, $results, $finalData); echo $finalData[0]; function converCurrency($from, $to, $amount) { $url = "http://www.google.com/finance/converter?a={$amount}&from={$from}&to={$to}"; $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); return $response; } ?> </body> </html>