Get currency exchange rate in PHP

/*
 * Functions gets currency exchange rate from rate-exchange.appspot.com server.
 * returns rate on success, else false
 */
function get_exchange_rate( $currency_from, $currency_to ) {
      $url = 'http://rate-exchange.appspot.com/currency?from=' . $currency_from . '&to=' . $currency_to;
      $exchange_rate = json_decode( file_get_contents( $url ) );
      return ( isset( $exchange_rate->rate ) ) ? $exchange_rate->rate : false;
}

Leave a Comment