SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 47 of 47
  1. #26
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again Spike - is there any way of doing that globally somehow please ? It's just that there can sometimes be up to about 60 different locations on the website where the different euro figures will be displayed and often change as well.

    Any help appreciated.

    Dez.

  2. #27
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    sadly not looks like you have a bit of work to do Dez! (it is only one word after all!)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #28
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The work isn't the issue really, it's knowing how and where to apply the changes.

    Is :

    $number = '14,637.48';
    echo round($number);
    // will give 14,637

    Supposed to go in the index.php file ? perhaps within the code below ?

    <table cellpadding="0" cellspacing="0" width="660">
    <tr>
    <td width="50">&nbsp;</td>
    <td>The current price, in euros, on the right :&nbsp; 1&euro;<br>
    <br>
    The equivalent price, in US dollars, automatically appearing to the right:&nbsp;<?=docurconversion(1,"USD")?> <br>
    <br>
    The equivalent price, in UK pounds, automatically appearing to the right:&nbsp;<?=docurconversion(1,"GBP")?> <br>
    &nbsp;</td>
    </tr>
    </table>

    I also have 3 other files that php_daemon kindly provided, should that code go in one of them instead please ?

    Any help appreciated.

    Dez.

  4. #29
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    There is the function docurconversion in index.php, to round the number change it to:
    PHP Code:
    function docurconversion($val$key)
    {
        global 
    $conversion_rates;

        if(
    $conversion_rates[$key])
        {
            
    #$newfigure = number_format($val * $conversion_rates[$key]['rate'], 2, '.', ',');
            
    $newfigure round($val $conversion_rates[$key]['rate']);
            
            return 
    "{$conversion_rates[$key]['label']}{$newfigure} ";
        }else return 
    "";

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #30
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's very much appreciated Spike - I'm very new to all this malarkey - so the help from you good guys here has been really helpful.

    One last thing - is there a quick, easy way to get the comma for the thousands at all please ?

    To turn this :
    215462

    Into this :
    215,462

    All the best.

    Dez.

  6. #31
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    That's what the original line in the function should have done....
    PHP Code:
     $newfigure number_format($val $conversion_rates[$key]['rate'], 2'.'','
    I take it it didn't for some reason?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #32
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had a feeling it should, but nope - it definitely doesn't do it :

    http://www.130605.com/currency

    All the best.

    Dez.

  8. #33
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Replace the said line with this:
    PHP Code:
    $newfigure number_format($val $conversion_rates[$key]['rate'], 0'.'','); 
    Basically I just changed the second param from 2 to 0, which is the decimals. So you don't need to use the round() function either.

    It should do the job.
    Saul

  9. #34
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Many thanks to you php_daemon and to you Spike - all now complete.

    The help from you both, and from Kevin earlier in the thread has been very much appreciated.

    Dez.

  10. #35
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You are very welcome.
    Saul

  11. #36
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by php_daemon
    Basically I just changed the second param from 2 to 0, which is the decimals. So you don't need to use the round() function either.

    It should do the job.
    That'll teach me to read the lines properly

    Glad it's working
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #37
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    That'll teach me to read the lines properly

    Glad it's working
    I'm just glad that you and php_daemon stepped in when you did


    All solved.

    Dez.
    Last edited by Dez; Jul 13, 2006 at 23:25.

  13. #38
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    this:
    Code:
    Current price, in euros, on the right:  11,493€
    
    The equivalent price, in UK pounds:: 7,947 
    
    The equivalent price, in US dollars: $14,621 
     
    
    
     	Current price, in euros, on the right :  311,586€
    
    The equivalent price, in UK pounds: 215,462 
    
    The equivalent price, in US dollars: $396,400
    Why?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #39
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Problem all solved - there's some great helpful people here - long live sitepoint forums

    Dez.
    Last edited by Dez; Aug 7, 2006 at 23:31.

  15. #40
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Using all of the code that has been kindly given in this thread, is there any way of the 4 rates on the page below automatically updating itself, rounding up or down to the nearest figure, so that there's only ever a maximum of 2 digits after the dot please ?

    http://www.130605.com/currency_rates/

    Code on that page :

    <?php
    include "config.php";

    $conversion_rates = array();
    $handle = @fopen($ratesfile, "r");
    if ($handle)
    {
    while (!feof($handle))
    {
    $buffer = fgets($handle, 4096);
    $pieces = explode(":", $buffer);
    $key = $pieces[0];
    $conversion_rates[$key]['label'] = $pieces[1];
    $conversion_rates[$key]['rate'] = $pieces[2];
    }
    fclose($handle);
    }

    function docurconversion($val, $key)
    {
    global $conversion_rates;

    if($conversion_rates[$key])
    {
    $newfigure = number_format($val * $conversion_rates[$key]['rate'], 0, '.', ',');
    return "{$conversion_rates[$key]['label']}{$newfigure} ";
    }else return "";
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-gb">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Currency</title>
    </head>
    <body bgcolor="#FFFFFF">
    <br>
    <br>
    <table cellpadding="0" cellspacing="0" width="660">
    <tr>
    <td width="50">&nbsp;</td>
    <td>
    1 British Pound =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Euros
    <br>
    <br>
    1 Euro =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; British Pounds
    <br>
    <br>
    <br>
    1 US Dollar =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Euros
    <br>
    <br>
    1 Euro =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; US Dollars<br>
    &nbsp;
    </td>
    </tr>
    </table>
    <br>
    <br>
    <br>
    <br>
    </body>
    </html>

    Any help very much appreciated.

    Dez.
    Last edited by Dez; Aug 8, 2006 at 00:49.

  16. #41
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Dez,
    theoretically it should already do that using number_format and I cant tell what's happening on your page as there are no figures!

    You can also have a look at money_format as another alternative.

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #42
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Thanks for the quick response Spike. The figures on the left of the page are the static ones and trying to get the relevant figures to appear on the right.

    http://www.130605.com/currency_rates/

    All the best.

    Dez.

  18. #43
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just been trying to solve this. Have added some more code - <?=docurconversion(1,"GBP")?> but still no joy ?

    Have run a cron job on converter.php as mentioned before in this thread.

    Any help much appreciated.

    Dez

    <?php
    include "config.php";

    $conversion_rates = array();
    $handle = @fopen($ratesfile, "r");
    if ($handle)
    {
    while (!feof($handle))
    {
    $buffer = fgets($handle, 4096);
    $pieces = explode(":", $buffer);
    $key = $pieces[0];
    $conversion_rates[$key]['label'] = $pieces[1];
    $conversion_rates[$key]['rate'] = $pieces[2];
    }
    fclose($handle);
    }

    function docurconversion($val, $key)
    {
    global $conversion_rates;

    if($conversion_rates[$key])
    {
    $newfigure = number_format($val * $conversion_rates[$key]['rate'], 0, '.', ',');
    return "{$conversion_rates[$key]['label']}{$newfigure} ";
    }else return "";
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-gb">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Currency</title>
    </head>
    <body bgcolor="#FFFFFF">
    <br>
    <br>
    <table cellpadding="0" cellspacing="0" width="660">
    <tr>
    <td width="50">&nbsp;</td>
    <td>
    1 British Pound =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?=docurconversion(1,"EUR")?> Euros
    <br>
    <br>
    1 Euro =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?=docurconversion(1,"GBP")?> British Pounds
    <br>
    <br>
    <br>
    1 US Dollar =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?=docurconversion(1,"EUR")?> Euros
    <br>
    <br>
    1 Euro =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <?=docurconversion(1,"USD")?> US Dollars<br>
    &nbsp;
    </td>
    </tr>
    </table>
    <br>
    <br>
    <br>
    <br>
    </body>
    </html>

  19. #44
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Is it best to start another thread ? This thread is still about currency conversions using php, but my last request is slightly different to the one that started it. I don't want to upset any netiquette on here and I definitely want to stay on the good side of the really helpful people here.

    Any help appreciated.

    Dez.

  20. #45
    SitePoint Enthusiast
    Join Date
    Mar 2006
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi
    this script i code it for a company it will convert the price from New Zealand Dollar to what ever depend on the user IP

    you can modify it in the way you like...

    that class i am using here is just for the user IP.

    thanks

    <?php


    /*


    ############################


    #Author:S.Mohammed Alsharaf#


    #Date:3/8/2006 #


    ############################


    */





    function convert_price($theAmount)


    {


    // include the class


    require_once('includes/i2m.class.php');





    // call the class ip2more


    $i2m = new ip2more();





    // vars for the currency, currency code, amount


    $theCurrency = $i2m->country['currency'];


    $theCurrency_code = $i2m->country['currency_code'] ;





    // if the amount is not number view error for webmaster


    // stop the function


    if (is_numeric ( $theAmount ) == false )


    {


    print "<div style='color:red'>Webmaster check this product price, it is contain string(s).</div>";


    return;


    }


    else


    {


    // if the user ip is unkown


    // stop the function


    // only the NZ price will be displayed


    if($theCurrency_code == 'UNKOWN')


    {


    return;


    }


    else


    {


    // if the user not in NZ convert


    if($theCurrency_code != 'NZD')


    {


    // url will pass the data to currnecy exchange site


    $url = 'http://www.xe.com/ucc/convert.cgi?From=NZD&To='.$theCurrency_code.'&Amount='.$theAmount;





    // make the url result in array


    $lines_array = file($url);





    // search the array


    $lines_string = implode('', $lines_array);





    // take what is between these tags


    eregi('<span style="font-size:14pt; font-weight:bold;">(.*)</span><br>', $lines_string, $head);





    // split the selected


    $lines = split("\n", $head[0]);





    // count the result lines


    $x = count($lines);





    // loop through them


    for ($i=0;$i<$x;$i++)


    {


    //print $lines[$i];


    }





    // clean unwanted text


    $line_0 = eregi_replace($lines[0], "" , $lines[0]);


    $line_1 = eregi_replace($lines[1], "" , $lines[1]);


    $line_2 = eregi_replace($lines[2], "" , $lines[2]);


    $line_3 = eregi_replace($lines[3], "" , $lines[3]);


    $line_4 = eregi_replace(" " .$theCurrency_code, "" , $lines[4]);





    // clean the html tags


    preg_match_all ("|<[^>]+>(.*)</[^>]+>|U", $line_4 ,$out, PREG_PATTERN_ORDER);





    // the result


    $result = $out[1][0].$out[1][1];





    // our price


    $final_result = round($result , 2);





    // print the price


    print $final_result.$theCurrency_code;





    } // end if currnecy is not NZ


    } // end if == UNKOWN


    } // end if is_numeric


    };








    print "the price in NZD = 23.40<br />";


    print "convert the price = ";


    convert_price('23.40');

    ?>

  21. #46
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by php_daemon View Post
    I've put it all together:

    1. I've modified converter.php. First of all I took took out configuration block to config.php as it's needed everywhere the conversion is used. Secondly, I've modified docurconversion() so it's more flexible to use.

    2. I've uploaded converter.php and config.php to my public_html. I've created rateslist.php (in public_html) and set it's permissions to 0777.

    3. I've edited index.php to do the conversion.

    I attached all of the files, too much to post here.

    Note that you need to run converter.php before you can use the conversion. You should set up the cron job to run it daily.

    Hope this helps.
    Ok, I know it's been a while, but had a feeling you were all missing me No seriously, I've been picking this project up every few months and having a go at it for a few days, not being successful and then trying again a few months later when I had another chance - well, I finally had a big chance yesterday and today, and have come across a problem, as mentioned before, there's about 100 files (that are in 100 folders), that need to get the info from the special currency code files, now if I sit all of the files that PHP Daemon kindly setup for me, into every one of the 100 folders, they all work ok, but I didn't really want to do that and have 100 cron jobs going off 2-3 times day as well.

    It would be great if all 100 files, just pointed to the one location for the files, (ideally, a folder called currency which had all of the relevant currency files in there) - is that possible please ?

    Any help appreciated.

    Dez.

  22. #47
    SitePoint Wizard
    Join Date
    Jun 2005
    Posts
    1,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's probably to do with absolute referencing as opposed to relative, but not sure where to make those changes. I don't mind paying a small amount if needs be.


Bookmarks

Posting Permissions

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