PHP Currency converter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AdrianH
    Recognized Expert Top Contributor
    • Feb 2007
    • 1251

    PHP Currency converter

    Does anyone know where I can get a PHP currency converter?


    Adrian
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Erm... from Google?

    (plus or minus 20 characters :P)

    Comment

    • AdrianH
      Recognized Expert Top Contributor
      • Feb 2007
      • 1251

      #3
      Originally posted by pbmods
      Erm... from Google?

      (plus or minus 20 characters :P)
      Ha ha .... ha! You think I didn't try Google? :p

      I did find a few, but they required registring to some site. Blech! And even when I did, I didn't get an email for at least an hour. Actually, I stopped looking after that. I gave them my spam account anyway. ;)

      When I tried using different key words I finally found some. I think the words were: Ajax, currency and converter. Pain in the ass trying to find somethings. :(

      But I did find it. Thanks.


      Adrian

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by AdrianH
        Ha ha .... ha! You think I didn't try Google? :p

        I did find a few, but they required registring to some site. Blech! And even when I did, I didn't get an email for at least an hour. Actually, I stopped looking after that. I gave them my spam account anyway. ;)

        When I tried using different key words I finally found some. I think the words were: Ajax, currency and converter. Pain in the ass trying to find somethings. :(

        But I did find it. Thanks.


        Adrian
        Ermmm. What currencies are you trying to convert?
        Do you need them updated in real time?
        I bet I could whip something up real fast.

        Comment

        • Motoma
          Recognized Expert Specialist
          • Jan 2007
          • 3236

          #5
          [code=php]
          <html>
          <head><title>Mo toma Pwnz0rz teh curency!!!!!11o ne
          </title></head>
          </body>
          <form method="post">

          <?php
          $currArr = array( 'Dollars' => 1, 'Euros' => .78, 'Linden' => 1000);

          if(isset($_POST['submit']))
          {
          $textBox = '<input type="text" name="dollars" value="'.$_POST['dollars'].'" />';
          $optionBox = '<select name="currency" >';
          foreach($currAr r as $name => $value)
          {
          if($_POST['currency'] == $value) $optionBox .= '<option value='.$value. ' selected>';
          else $optionBox .= '<option value='.$value. ' >';
          $optionBox .= $name;
          }
          $optionBox .= '</select>';
          $result = '<input type="text" name="result" value="'.$_POST['dollars'] * $_POST['currency'].'">';
          }
          else
          {
          $textBox = '<input type="text" name="dollars" />';
          $optionBox = '<select name="currency" >';
          foreach($currAr r as $name => $value) $optionBox .= '<option value='.$value. ' >'.$name;
          $optionBox .= '</select>';
          $result = '<input type="text" name="result" />';
          }

          echo $textBox.$optio nBox.'<input type="submit" name="submit">' .$result;
          ?>

          </form>
          </body>
          </html>
          [/code]

          Don't make fun of me if it doesn't work.

          Comment

          • AdrianH
            Recognized Expert Top Contributor
            • Feb 2007
            • 1251

            #6
            Originally posted by Motoma
            [code=php]
            <html>
            <head><title>Mo toma Pwnz0rz teh curency!!!!!11o ne
            </title></head>
            </body>
            <form method="post">

            <?php
            $currArr = array( 'Dollars' => 1, 'Euros' => .78, 'Linden' => 1000);

            if(isset($_POST['submit']))
            {
            $textBox = '<input type="text" name="dollars" value="'.$_POST['dollars'].'" />';
            $optionBox = '<select name="currency" >';
            foreach($currAr r as $name => $value)
            {
            if($_POST['currency'] == $value) $optionBox .= '<option value='.$value. ' selected>';
            else $optionBox .= '<option value='.$value. ' >';
            $optionBox .= $name;
            }
            $optionBox .= '</select>';
            $result = '<input type="text" name="result" value="'.$_POST['dollars'] * $_POST['currency'].'">';
            }
            else
            {
            $textBox = '<input type="text" name="dollars" />';
            $optionBox = '<select name="currency" >';
            foreach($currAr r as $name => $value) $optionBox .= '<option value='.$value. ' >'.$name;
            $optionBox .= '</select>';
            $result = '<input type="text" name="result" />';
            }

            echo $textBox.$optio nBox.'<input type="submit" name="submit">' .$result;
            ?>

            </form>
            </body>
            </html>
            [/code]

            Don't make fun of me if it doesn't work.
            HA-HA! (bully from the Simpsons) ;)

            I've not tried it, but I would like it to convert all different types. Apperently, the one I've got and am still looking at will download a csv file from yahoo's finantial pages and then it will be able to convert and update using AJAX.

            I'm still trying to get it to work. :(


            Adrian

            Comment

            • Motoma
              Recognized Expert Specialist
              • Jan 2007
              • 3236

              #7
              Originally posted by AdrianH
              HA-HA! (bully from the Simpsons) ;)

              I've not tried it, but I would like it to convert all different types. Apperently, the one I've got and am still looking at will download a csv file from yahoo's finantial pages and then it will be able to convert and update using AJAX.

              I'm still trying to get it to work. :(

              Adrian
              You could do the same thing with mine: use fopen and fgetcsv to read the CSV file, and write the data to an associative array. Take the input currency, convert to a standard medium, and convert to your output currency.
              I like the associative array method better, as it is easier to use: you don't need to keep track of every currency's exchange rate with every other currency (an n squared problem). Instead you keep track of every currency in relation to a base (in my case, dollars) and do all conversions with that.
              The basic algorithm would be:

              (source amount) / (source rate) * (currency rate)

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by Motoma
                [code=php]
                <html>
                <head><title>Mo toma Pwnz0rz teh curency!!!!!11o ne
                </title></head>
                </body>
                <form method="post">

                <?php
                $currArr = array( 'Dollars' => 1, 'Euros' => .78, 'Linden' => 1000);

                if(isset($_POST['submit']))
                {
                $textBox = '<input type="text" name="dollars" value="'.$_POST['dollars'].'" />';
                $optionBox = '<select name="currency" >';
                foreach($currAr r as $name => $value)
                {
                if($_POST['currency'] == $value) $optionBox .= '<option value='.$value. ' selected>';
                else $optionBox .= '<option value='.$value. ' >';
                $optionBox .= $name;
                }
                $optionBox .= '</select>';
                $result = '<input type="text" name="result" value="'.$_POST['dollars'] * $_POST['currency'].'">';
                }
                else
                {
                $textBox = '<input type="text" name="dollars" />';
                $optionBox = '<select name="currency" >';
                foreach($currAr r as $name => $value) $optionBox .= '<option value='.$value. ' >'.$name;
                $optionBox .= '</select>';
                $result = '<input type="text" name="result" />';
                }

                echo $textBox.$optio nBox.'<input type="submit" name="submit">' .$result;
                ?>

                </form>
                </body>
                </html>
                [/code]

                Don't make fun of me if it doesn't work.
                you could at least have made it possible for users to specify the conversion rates ...

                Comment

                • Purple
                  Recognized Expert Contributor
                  • May 2007
                  • 404

                  #9
                  Hi,

                  did you take a look at xe.com ?

                  xe.com

                  Purple

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by Purple
                    Hi,

                    did you take a look at xe.com ?

                    xe.com

                    Purple
                    Long form to fill in but the screen shot looks better than motoma's!

                    Comment

                    • Motoma
                      Recognized Expert Specialist
                      • Jan 2007
                      • 3236

                      #11
                      Originally posted by r035198x
                      Long form to fill in but the screen shot looks better than motoma's!
                      You think you're pretty smart, what with your 5000 posts eh? Won't be feeling so spiffy once I go and delete all of your posts. You'll be sitting there with roughly a dozen in your name.

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by Motoma
                        You think you're pretty smart, what with your 5000 posts eh? Won't be feeling so spiffy once I go and delete all of your posts. You'll be sitting there with roughly a dozen in your name.
                        Don't forget my arm is longer than yours and reaches all the small and nasty corners.

                        Comment

                        • Motoma
                          Recognized Expert Specialist
                          • Jan 2007
                          • 3236

                          #13
                          Originally posted by r035198x
                          Don't forget my arm is longer than yours and reaches all the small and nasty corners.
                          Meh.
                          'nuff said.

                          Comment

                          Working...