IT Community - Software Programming, Web Development and Technical Support

Embedded Currency Conversion

This is a discussion on Embedded Currency Conversion within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Can anyone please advise if it is possible to embed some sort of code into a non-dynamic site (XHTML ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 08-24-2007, 06:02 AM
Alkazar Alkazar is offline
D-Web Trainee
 
Join Date: Aug 2007
Posts: 2
Alkazar is on a distinguished road
Question Embedded Currency Conversion

Can anyone please advise if it is possible to embed some sort of code into a non-dynamic site (XHTML and CSS) to enable an amount in US $ to be automatically displayed in another currency alongside the dollar price?

I've seen sites that offer free online exchange rate calculators (eg. XE.com - The World's Favorite Currency and Foreign Exchange Site) that can be embedded on my site but the user needs to enter amounts and currencies etc., which I don't want.

I just want the US dollar price on my HTML page to be used as the input amount, the output currency would be predetermined (i.e. not user selectable) and then a field to display the returned converted amount.

Is this possible without setting up a full database driven site as I'm only just getting my head around CSS & HTML and have no PHP experience other than recently helping to set up a Zen-Cart site for a relative. I noticed that Zen-Cart uses some sort of open-source online exchange rate service and it got me wondering.

Many thanks in advance.

Last edited by Alkazar : 08-24-2007 at 08:32 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 08-27-2007, 06:57 AM
shiva shiva is offline
Super Moderator
 
Join Date: Feb 2007
Location: Chennai
Posts: 53
shiva is on a distinguished road
Send a message via AIM to shiva Send a message via MSN to shiva
Default Re: Embedded Currency Conversion

Hi Alkazar,

I don't think you need a fully database driven site to convert currency and show it in your HTML site..

As seen in some sites, they just spider through other sites which have the currency conversion modules and get the conversion details from them...

So what you need a PHP Page to do the spidering or grabbing functionality...

Attached is a PHP Script which will take the INPUT & OUTPUT Currencies & the Input Currency Value and get the converted output currency Value from finance.yahoo.com

PHP Code:
    function get_conversion($cur_from,$cur_to,$val){

            if(
strlen($cur_from)==0){
                
$cur_from "USD";
            }
            if(
strlen($cur_to)==0){
                
$cur_from "PHP";
            }
            
$host="finance.yahoo.com";
            
$fp = @fsockopen($host80$errno$errstr30);
            if (!
$fp)
            {
                
$errorstr="$errstr ($errno)<br />\n";
                return 
false;
            }
            else
            {
                
$file="/d/quotes.csv";
                
$str "?s=".$cur_from.$cur_to."=X&f=sl1d1t1ba&e=.csv";
                
$out "GET ".$file.$str." HTTP/1.0\r\n";
                
$out .= "Host: www.yahoo.com\r\n";
                
$out .= "Connection: Close\r\n\r\n";
                @
fputs($fp$out);
                while (!@
feof($fp))
                {
                    
$data .= @fgets($fp128);
                }
                @
fclose($fp);
                @
preg_match("/^(.*?)\r?\n\r?\n(.*)/s"$data$match);
                
$data =$match[2];
                
$search = array ("'<script[^>]*?>.*?</script>'si","'<[\/\!]*?[^<>]*?>'si","'([\r\n])[\s]+'","'&(quot|#34);'i","'&(amp|#38);'i","'&(lt|#60);'i","'&(gt|#62);'i","'&(nbsp|#160);'i","'&(iexcl|#161);'i","'&(cent|#162);'i","'&(pound|#163);'i","'&(copy|#169);'i","'&#(\d+);'e");
                
$replace = array ("","","\\1","\"","&","<",">"," ",chr(161),chr(162),chr(163),chr(169),"chr(\\1)");
                
$data = @preg_replace($search$replace$data);
                
$result split(",",$data);
                return (
$result[1] * $val);
            }
//else
    
}//end get_conversion 
Hope this helps!!!

Thanks
Shiva...
__________________
The real voyage of discovery consists not in seeking new landscapes, but in having new eyes
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Currency format Kirubhananth ASP and ASP.NET Programming 2 03-13-2008 02:26 AM
What is embedded style? How to link? itbarota HTML, CSS and Javascript Coding Techniques 1 09-12-2007 12:25 AM
How to Create an Excel Macro that converts currency in numbers into words? itbarota VB.NET Programming 2 08-08-2007 05:23 AM
embedded webserver theone HTML, CSS and Javascript Coding Techniques 0 07-30-2007 05:17 AM
How to Create word Macro that converts currency in numbers into words? itbarota VB.NET Programming 1 07-25-2007 03:03 AM


All times are GMT -7. The time now is 06:47 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0