lional Posted January 26, 2007 Share Posted January 26, 2007 Hi allI am looking for a script that can dynamically convert currency. Specifically I want to convert from British Pounds to South African Rands and vice versa.Any suggestionsAny help will be appreciatedThanksLional Quote Link to comment https://forums.phpfreaks.com/topic/35763-currency-converter/ Share on other sites More sharing options...
jumpenjuhosaphat Posted January 26, 2007 Share Posted January 26, 2007 What do you mean by dynamically?Basically it would be a simple script that would just perform a simple math problem. If you mean dynamically, in that the page doesn't need to be refreshed, you would probably need to use javascript for that. Quote Link to comment https://forums.phpfreaks.com/topic/35763-currency-converter/#findComment-169545 Share on other sites More sharing options...
lional Posted January 26, 2007 Author Share Posted January 26, 2007 No what I need is a page that will automatically take the exchange rate at a given time in the day and automatically update the currency with the exchange rate.ThanksLional Quote Link to comment https://forums.phpfreaks.com/topic/35763-currency-converter/#findComment-169692 Share on other sites More sharing options...
HuggieBear Posted January 26, 2007 Share Posted January 26, 2007 OK, this is actually quite simple. First you have to decide:A) Where's the content going to come from e.g. text file, website html, xml request to aggregator etc.B) If you need to parse the value once it's returned.C) How you want to output it.I have a page that connects to Reuters website, gets a share price for a specific symbol, returns it to a script of mine and then tells me what my net share worth is, how many of each share I have, what I paid for them originally, and how much I've gained or lost on them.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/35763-currency-converter/#findComment-169695 Share on other sites More sharing options...
lional Posted January 26, 2007 Author Share Posted January 26, 2007 What I would like to do is to get it for a website.I am writing a site where the currency is in pounds. So what I would like to do is to capture the exchange rate for that day, write it to a field in the database, and when I run the script that needs the currency to be converted, it pulls the value from the database and does the conversion.ThanksLional Quote Link to comment https://forums.phpfreaks.com/topic/35763-currency-converter/#findComment-169701 Share on other sites More sharing options...
HuggieBear Posted January 26, 2007 Share Posted January 26, 2007 I just knocked this up. It's messy, but it will give you an idea of how it's done. You'd be better using an XML data feed if possible though. There's plenty of them out there.RegardsHuggie[code]<?php// URL of currency data$url = "http://newsvote.bbc.co.uk/1/shared/fds/hi/business/market_data/currency/11/12/default.stm";// Connect to the URL and pull the data down into a string$raw_data = file_get_contents($url);// Match the currency valuepreg_match('/South African Rand.*?right">([^<]+)/is', $raw_data, $matches);// Format to 2 decimal places$ex_rate = number_format($matches[1], 2, '.', '');// Total GBP$p = "15.00";// Echo some resultsecho "The product you selected is £" . $p . " GBP, That's approximately " . number_format($p * $ex_rate, 2) . " ZRA*<br><br>";echo "* price based on a rounded exchange rate of " . $matches[1];?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35763-currency-converter/#findComment-169728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.