Curl Currency Converter

I am looking for a currency converter using curl
go-fastAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

syedasimmeesaqCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.