www.webdeveloper.com
Results 1 to 6 of 6

Thread: Automatic conversion of a Euro value to Pounds

  1. #1
    Join Date
    May 2014
    Posts
    1

    Question Automatic conversion of a Euro value to Pounds

    Creating a web page I want to inform visitors the price of an item that is available elsewhere. I could say just 125.87 but I would rather have an underlining function that automatically converted it to pounds depending on the exchange rate of the day. Is this a bridge too far or is it indeed possible? If so how?

    David

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290
    The European Central Bank publish many things about Foreign exchange references rates...

    At first this page http://www.ecb.europa.eu/euro.html give the daily reference rates which are usually updated by 3 p.m. C.E.T. They are based on a regular daily concertation procedure between central banks across Europe and worldwide, which normally takes place at 2.15 p.m. CET.

    Second a special page for developers propose many PHP code to parse the data

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290
    Here is a newly created Euro universal converisseur. I will still put in a few points to make...
    Last edited by 007Julien; 05-10-2014 at 07:23 PM.

  4. #4
    Join Date
    Nov 2010
    Posts
    1,276
    you can use yql to get the current exchange rate, then just multiply as you need to...

    Code:
    <script>
     
    
      function parseExchangeRate(data) {
        var name = data.query.results.row.name;
        var rate = parseFloat(data.query.results.row.rate, 10);
        alert("Exchange rate " + name + " is " + rate);
      }
      
        var script = document.createElement('script');
        script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3DEURGBP%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
        document.body.appendChild(script);
      
    </script>

  5. #5
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290
    Try to upload this php page on your server
    PHP Code:
    <?php

        header
    ("expires: mon, 26 jul 1997 05:00:00 gmt");
        
    header("cache-control: no-cache, must-revalidate");
        
    header("pragma: no-cache");
        
    header("Content-Type:text/html;charset=utf-8");

    /*    The reference rates are usually updated by 3 p.m. C.E.T.
        They are based on a regular daily concertation procedure between central banks
        across Europe and worldwide, which normally takes place at 2.15 p.m. CET.*/

        
    date_default_timezone_set('Europe/Paris');
        
    $fileName='ECB_GB_pound_rate.txt';
        
    $okFle=false;
        if (
    file_exists($fileName) && ($tms=filemtime($fileName))) {
            
    $dteLstMdf=new DateTime(date ("Y-m-d H:i:s.",$tms));
    //        echo "Date of the last file : ".$dteLstMdf->format('Y-m-d H:i:s')."<br>";
            
    $dtePub=clone($dteLstMdf);
            
    $dtePub->setTime(15,15);
            if (
    $dtePub<$dteLstMdf$dtePub->modify("-1 day");
    //        echo "First possible pubDate after modif : ".$dtePub->format('Y-m-d H:i:s')."<br>";
            
    while(5<$dtePub->format('N')) $dtePub->modify("+1 day");
    //        echo "First possible bussness day after modif : ".$dtePub->format('Y-m-d H:i:s')."<br>";
            
    $okFle=new DateTime()<$dtePub;
        }

        if (
    $okFle) { $gb_pound_rate=trim(file_get_contents(ECB_GB_pound_rate.txt));}
        else {
    // Lecture des taux
            
    $HTMLines=file("http://www.ecb.europa.eu/euro.html");
            
    $strDte='var ECB_date="';
            
    $strRte='var ECB_GBP_rate="';
            foreach (
    $HTMLines as $v) {$w=trim($v);
                if (
    preg_match("/>Date: ([^<]+)</",$w,$m)) $strDte.=$m[1].'";'.chr(13).chr(10);
                  if (
    preg_match("/([\w ]+)\(GBP\)\s?=\s?([\d.]+)/",$w,$m)) $strRte.=$m[2].'";'.chr(13).chr(10);
            }
            
    $gb_pound_rate="$strDte$strRte";
            
    file_put_contents($fileName,"$strDte$strRte");
         }
    ?>
    <!doctype html>
    <html lang="fr">
    <head>
      <meta charset="utf-8">
      <title>Euro pound converter</title>
    <style type="text/css">
    body {font-family:Georgia,Serif;background:#000;color:#fff}
    #pge {width:600px;margin:30px auto;padding:13px;background:#888;}
    </style>
    </head>
    <body>
    <div id="pge"><fieldset><legend>Consersion Euro pounds</legend>
        <p id="rsp"></p>
    </fieldset></div>
    <script>
    <?php echo $gb_pound_rate?>
    // Your script
        document.getElementById('rsp').innerHTML='At  '+ECB_date+' according to ECB :<br> 1,000 Euros are '+(ECB_GBP_rate*1000).toFixed(2)+' Pounds, ';
        document.getElementById('rsp').innerHTML+='then 1,000 Pounds are '+(1000/ECB_GBP_rate).toFixed(2).replace(/(\d)(?=(\d{3})+\b)/g,'$1,')+' Euros.';
    </script>
    </body>
    </html>
    This page store the rate in a file and use this file without new possible publications from ECB. See the resulting script on this page which allow all calculation with the rate.
    Last edited by 007Julien; 05-12-2014 at 04:34 PM. Reason: complements

  6. #6
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.18541 seconds
  • Memory Usage 2,914KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates