Jump to content

currency converter


lional

Recommended Posts

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.

Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/35763-currency-converter/#findComment-169695
Share on other sites

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.

Thanks

Lional
Link to comment
https://forums.phpfreaks.com/topic/35763-currency-converter/#findComment-169701
Share on other sites

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.

Regards
Huggie

[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 value
preg_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 results
echo "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]
Link to comment
https://forums.phpfreaks.com/topic/35763-currency-converter/#findComment-169728
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.