function get_currency_rate($currencySource) {
if (isset($currencySource)) {
$feed = $currencySource;
} else {
echo 'Feed not found. Check URL';
}
if (!$feed) {
echo('Feed not found');
}
$xml = new SimpleXmlElement($feed);
$rate = get_rate($xml, 15); //EUR
if ($feed == 'http://themoneyconverter.com/rss-feed/USD/rss.xml') {
$rate = get_rate($xml, 16); //GBP
} else {
$rate = get_rate($xml, 56); //USD
}
}
I would prefer to pass in the values 15, 16, 56 and the URL 'http://themoneyconverter.com/rss-feed/USD/rss.xml' rather than hard coding them into the function.
Below is the get_rate function.
// Get and return currency rate
// Perform regular expression to extrat numeric data
// Split title string to extract currency title
function get_rate(SimpleXMLElement $xml, $xmlTagPosition) {
$currency['rate'] = $xml->channel->item[$xmlTagPosition]->description;
preg_match('/([0-9]+\.[0-9]+)/', $currency['rate'], $matches);
$rate = $matches[0];
$title['rate'] = $xml->channel->item[$xmlTagPosition]->title;
$title = explode('/', $title['rate']);
$title = $title[0];
echo $rate . ' ' . $title . '<br />';
}
The feed URL's are set in my cityConfig.php script as below:
// Feed URL's //
$theMoneyConverter = 'http://themoneyconverter.com/rss-feed/';
// Define arrays //
$cities = array('London', 'New York', 'Paris');
$currencyHeadings = array('London - 1 British Pound Sterling', 'New York - 1 US Dollar', 'Paris - 1 Euro');
$currencySource = array($theMoneyConverter . 'GBP/rss.xml', $theMoneyConverter . 'USD/rss.xml', $theMoneyConverter . 'EUR/rss.xml');
$currencyId = array(15, 16, 56);
?>
Notice the $currencyId array values are the same as those hard coded into the get_currency_rate function. I tried passing in a second parameter for the $currencyId to no avail. Any ideas where I'm going wrong?
Thanks in advance

New Topic/Question
Reply



MultiQuote





|