|
Dear Team, Greetings ! I have a requirement to pull foreign exchange rate from the potential site. I managed to get a php code which is as belows.
<?php
/**
* Live currency exchange script.
* This script allows you to retrieve the current currency exchanges, live, from the internet.
*
* This script is developed by Tim Visee, for educational purposes.
* The Yahoo currency exchange API is used to retrieve the live exchange rates.
*
* ---
*
* Script usage:
* To retrieve the current currency exchange rates for two currencies, simply make a request to this script with the
* parameters that are described bellow.
*
* Script parameters:
* - from: Three letter code for base currency.
* - to: Three letter code for target currency.
*
* For example, to get the exchange rate for EUR to USD, use the following parameters:
* index.php?from=EUR&to=USD
* The currency exchange rate is returned as a numerical value, with a dot as decimal delimiter.
*
* The string 'ERROR' is returned if an error occurred. For example, if the current exchange rate couldn't be retrieved,
* or if the three letter currency code is invalid.
*
* ---
*
* @author Tim Visee
* @website http://timvisee.com/
* @copyright Copyright (c) Tim Visee 2015. All rights reserved.
*/
// Disable all PHP errors
error_reporting(0);
ini_set('display_errors', 0);
/**
* Show an error, and stop the script.
*/
function showError() {
die('ERROR');
}
// Make sure the currencies are set
if(!isset($_GET['from']) || !isset($_GET['from']))
showError();
// Get the currencies to convert
$from = trim(strtoupper($_GET['from']));
$to = trim(strtoupper($_GET['to']));
// Make sure both currency identifiers are three characters long
if(strlen($from) != 3 || strlen($to) != 3)
showError();
// Create the conversion string
$conversionString = $from . $to;
// Do the whole exchange rate retrieval process in a try-catch block to handle possible errors
try {
// Get the current exchange
$url = "http://query.yahooapis.com/v1/public/yql?env=store://datatables.org/alltableswithkeys&q=SELECT%20*%20FROM%20yahoo.finance.xchange%20WHERE%20pair%20IN%20%28%22" . $conversionString . "%22%29";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);
$xml = curl_exec($ch);
// Parse the XML data
$xmlData = new SimpleXMLElement($xml);
// Make sure the rate is set
if(!isset($xmlData->results->rate->Rate))
showError();
// Get and parse the exchange rate as a float
$exchangeRate = floatval($xmlData->results->rate->Rate);
// Echo the actual exchange rate
echo $exchangeRate;
} catch(Exception $e) {
// Show an error page
showError();
}
I am on phprunner 9.7 on windows 7 sp1 with xampp control panel v3.2.2 php version 5.6.30. I have 2 questions:-
- when I put a date in first column and select currency pair, I need to fetch the exchange rate from internet into initial exchange rate column based on the date given in this first column, I believe above code is one of the means to retrieve rate, I am not yet sure, if that is the code required, if otherwise, please suggest.
- The third column is of system date in phprunner, the phprunner should retrieve the system date exchange rate based on the date given and pair already selected in the fourth column named todays foreign exchange rate column, the system date column will be read only. So the system will have initial foreign exchange rate and todays foreign exchange rate in a single record with 2 dates.
I am also licensed holder of phprunner 9.8. Team, please help me achieve this scenario, I am a complete noob in php, if any changes or procedure is required, please let me know the detailed procedure and column names required. I will appreciate if the exchange rate comes automatically after putting date and exchange rate pair in the 2 dates columns. Your knowledge/ support/ patience is highly appreciated. Kind Regards.
I appeal to the experts, please help me in this post. Thank you in advance.
|