Curl Currency Converter

I am looking for a currency converter using curl
go-fastAsked:
Who is Participating?
 
syedasimmeesaqConnect With a Mentor Commented:
hmm i got this one from web
XXXX
<?php
function exchangeRate( $amount, $currency, $exchangeIn )
{
$googleQuery = $amount .   . $currency .  in  . $exchangeIn;
$googleQuery = urlEncode( $googleQuery );
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, http://www.google.com/search?q= . $googleQuery);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
$file_contents = strip_tags( $file_contents );
curl_close($ch);
$matches = array();
preg_match( /= (([0-9]|\.|,|\ )*)/, $file_contents, $matches );
return $matches[1] ? $matches[1] : false;
}
?>
exchange_rate.php
XXXX
Guessed what it does yet, its a simple currency converter it uses Googles google conversion search to take our content and convert it to what ever we want. The code is PHP and uses CURL you could have used FOpen or similar but I like CURL.
<?php require( 'exchange_rate.php' ); echo '£50 ($' . exchangeRate( 50, 'GBP', 'usd' ) ')'; ?>

This code is used to call the conversion in your document, in the above example we wish to display £50 and its equivalent dollars
it does so by requesting http://www.google.com/search?hl=en&q=50GBP+in+USD from Google search this returns a single result which is easy to strip of content to get the answer.
0
 
syedasimmeesaqCommented:
clean snipet below.
Hope it helps
<?php
function exchangeRate( $amount, $currency, $exchangeIn )
{
$googleQuery = $amount . ' ' . $currency . 'in '. $exchangeIn;
$googleQuery = urlEncode( $googleQuery );
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://www.google.com/search?q=' . $googleQuery);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
$file_contents = strip_tags( $file_contents );
curl_close($ch);
$matches = array();
preg_match( '/= (([0-9]|\.|,|\ )*)/', $file_contents, $matches );
return $matches[1] ? $matches[1] : false;
}
?>

Open in new window

0
 
CWS (haripriya)Commented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept: syedasimmeesaq {http:#20816442}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

cyberwebservice
Experts Exchange Cleanup Volunteer
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
All Courses

From novice to tech pro — start learning today.