Currency Converter API

After looking for a currency converter api,

I finally managed to write a few lines my own in PHP using the google api for currency converter.

//You can use ISO standard country codes for currency here
$amount=1;
$fr="USD";
$to="PHP";
$url="http://www.google.com/ig/calculator?hl=en&q=".$amount.$fr."=?".$to;
$handle = @fopen($url, 'r');
if ($handle) {
    $result = fgets($handle, 4096);
    fclose($handle);
}
//Explode result
$result = explode(",",substr($result,1,strlen($result)-2));
$newres = explode(":",substr($result[1],2,strlen($result[1])-2));
$newres=trim($newres[1]);
$newres = explode(" ",substr($newres,1,strlen($newres)-2));
$newrate=round(preg_replace('/[^\w\d_ -.]/si', '', $newres[0]),2);
if('error: ""'<>trim($result[2])){
    $newrate="Invalid Query";
}else
    {
        $newrate = $amount." ".$fr." = ".$newrate." ".$to;
    }
echo $newrate;
?>

 

Hope this help!

Your Guide to Wireless Internet
and High-Speed Internet Providers
and Technology
www.wirelessinternet.net

10 Responses to "Currency Converter API"

Leave a Comment

*