Saturday, November 22, 2008

Automatic currency updates via RSS

last day i make php script to get foreign currency exchange updates value...
firstly, i worked on to get US($) to INR conversion....
it's possible for me to get that value via RSS(Really simple syndication).
RSS is a family of web-feed format. it's format are specified using XML language. it's useful to get automatic updates value of any type like..
1. share Maket
2. Temperature value
3. News Headlines
4. Audio/Video
5. foreign currency exchange value... like that..

//source code for the currency-exchange rate of US-INR
// PHP Script

if ($currency != '')
//This pulls the data from the IMF, which is where sites like get their information
$er_url = "".$currency."xml";
$rates = '';
//Try using fopen since it's more supported
if (ini_get('allow_url_fopen'))
//file_get_contents() only exists in PHP 4.3.0 and above
$rates = file_get_contents("");

//Parse the XML file down to the important stuff and break it up into an array
$rates = substr($rates, strpos($rates, ''), -20);
$rates = explode("\n", $rates);
echo "Update Currency Value: ".$rates1."";
echo $rates[124];

// End of the PHP Script

one thing is to be keep in mind i.e. the php.ini (You can locate it in /etc/php.ini in any linux server) that must have "allow_url_fopen" value should be "On".
Use of file_get_contents() function in this script will worked only in php version 4.3.0 or above. that script ... and enjoy the output..:)