51 Responses

  1. Iuri
    Iuri at | | Reply

    Nice code mate!
    Does it work with australian dollars as well?

  2. Mihai
    Mihai at | | Reply

    Yes, I admire your “do it your way” style, and thanks for sharing. What your professional blog needs (and what I’ve seen on other technical blogs) is a deploy page for the examples, or an embedded area within the post, for dummies to see the exact result and the implementation.

  3. Mattew Morris
    Mattew Morris at | | Reply

    Hi, any idea if there’s a way to force Google to return values to the nearest whole number? I’ve tried to use PHP’s “round” function, but it can’t deal with the commas that google returns to seperate thousands up. Thanks!

  4. Mattew Morris
    Mattew Morris at | | Reply

    Sorry, correction – Google returns a space after the thousand. “1300″ returns as “1 300″

  5. Mattew Morris
    Mattew Morris at | | Reply

    For anyone who’s interested – I solved my problem above by using the following:

    It replaces the space that Google returns after the “thousand” and then rounds down to the nearest whole number.

  6. Naga sunford
    Naga sunford at | | Reply

    hello
    is any body to know the conversion of code in php from usd to Euro.becaZ im a php learner and beginner. so any body could help me

    FYI

    i have two text box 1 for dollar and another for euro .
    if type the value of us dollar in a text then click convert button it will automatically changed in Euro value in the another text box

  7. jaswant
    jaswant at | | Reply

    where is the script to download. Downlod link is not working.

  8. NS
    NS at | | Reply

    I also got an error why I tried downloading the file. Can you correct this?

    Thanks.

  9. Mattew Morris
    Mattew Morris at | | Reply

    Hmm, the example above didn’t paste properly….

  10. Manic
    Manic at | | Reply

    Nice one, I used this to loop through a bunch of currency codes and get rates. I found that the function, in some cases, returns a value that is not a currency conversion.

    To solve this you need to add a pregmatch that checks to see if the resulting page is infact a conversion result page and not a standard google search result list.

  11. Seb
    Seb at | | Reply

    I have used the script but it returns the whole string after “= “.

    So I have modified the regular expression into:

    I am not an expert in regular expressions I tried to make it work with any digit, the white space, the “.” and the “,”.

    However, if you put large amounts google will return, for example, the word “million” and divide the result by one million, so this means that the function needs to be further “cleaned”.

    if you enter:

    1000000 gbp in usd

    Google returns:

    1 000 000 British pounds = 1.9866 million U.S. dollars

    any idea?

  12. Radu
    Radu at | | Reply

    In the end I used BNR’s official currency data (it’s only for RON):
    http://www.bnro.ro/nbrfxrates.xml

  13. Jrok
    Jrok at | | Reply

    Hey I’m having the same issue with removing the space when the ‘price’ is in the thousands, AND rounding it out to two decimal places. This is SO perfect for what I’m trying to do, but dang, not close enough!

    I’ve tried str_replace with  , and with %20; and I’m at a loss — please help!

  14. Jrok
    Jrok at | | Reply

    GAH…. sometimes my brain gets stuck in a ‘rut’ of how to go about these things — thank you.

  15. Emmanuel
    Emmanuel at | | Reply

    Hey, it seems to work perfect, but it is displaying 5 decimals. Is there any way that I can make it display only 2?

  16. Emmanuel
    Emmanuel at | | Reply

    Nevermind, I just figured out, but thank you so much anyways. It works amazingly perfect

  17. Mike VandeVelde
    Mike VandeVelde at | | Reply

    Hi, this looks like it would work great, except that Google returns something like:

    403 ForbiddenGoogle Error ForbiddenYour client does not have permission to get URL /search?q=1+cad+in+eur from this server. (Client IP address: x.x.x.x) Please see Google’s Terms of Service posted at http://www.google.com/terms_of_service.html If you believe that you have received this response in error, please report your problem blah blah blah

    I guess they don’t like you hitting their search with a script? Have you ever seen this issue? Is this something they just started doing recently?

    Thanks for posting this anyway, but oh well back to the drawing board I guess…

  18. laforge
    laforge at | | Reply

    Very handy script. Thanks for this.

  19. Martin Walker
    Martin Walker at | | Reply

    This is great!! Thanks.

    I just implemented the code to translate a fixed Euro product price into Danish krona, rounding to the nearest kr. Works beautifully. And so much simpler than anything else out there. Well done.

    Here’s the page: http://www.mindsparke.dk/buy.php

    Martin

  20. Martin Walker
    Martin Walker at | | Reply

    Hi Tudor.

    What makes you say that? I’m curious.

    Martin

  21. Martin Walker
    Martin Walker at | | Reply

    Ah, I see. Thanks, Tudor.

    The program presents an unusual problem in this regard. It requires a good deal of commitment and effort on the part of the user before he or she would be able to say whether it worked for them or not. The user must train for no less than ten days before the results begin to appear. This is because it is stimulating changes in working memory and focus. The training is also particularly difficult for the first few days.

    This means that someone who purchases the software to perform the usual product evaluation (how does it look, what will it do for me) will find themselves immediately faced with the need to commit. (Reviewers have agreed with the conclusion that a trial version would be a bad idea.)

    Instead I offer the full, unconditional money-back guarantee, plus an additional $40 if someone commits to ten days and doesn’t find it useful. (I’ve had a few returns, but no one has yet taken me up on that ten day offer!!)

    If anyone contacts me wanting to try the software, I am always more than willing to supply a copy.

    Martin

  22. Lars Sorhus
    Lars Sorhus at | | Reply

    Hi Guys,

    Here’s a much easier way:

    http://www.google.com/ig/calculator?hl=en&q=2.5AUD=?GBP

    It does output it as JSON, but it’s consistent and easilly parsable.

    Cheers,

    Lars

  23. Better PHP exchange rate script :: Get the exchange rate in PHP | Tudor Barbu's professional blog

    [...] a project I was working on back then. And, following the will of the Force, I’ve came up with this script, that queries Google for the exchange rate and parses the answer page with regular [...]

  24. sohail
    sohail at | | Reply

    Plz tell me step by step how to use this script. I need to insert it in my html webpage.. please help..

  25. sohail
    sohail at | | Reply

    I hve PHP in my server.. I meant to say.. I need to embed this code in html page…

  26. sohail
    sohail at | | Reply

    Plz tell me step by step procedure how to use this script. I need to insert it in my html webpage.. please help . I hve PHP in my server.

  27. sohail
    sohail at | | Reply

    I am not webmaster or sum thing. I am going to be professional in web related stuffs, but this is really urgent for me. I want to insert this converter in my non profit website. Please help.

  28. Currency Exchange with PHP | thisMayhem

    [...] Source [...]

  29. Suresh
    Suresh at | | Reply

    Thanks man for this code. it helped me a lot… :)

  30. 1337ingDisorder
    1337ingDisorder at | | Reply

    Hi Tudor,

    This script has been working great for months but it seems to have broken today, I suspect Google may have changed the format of their output or something to that effect.

    The error output it’s now giving is as follows:

    PHP Notice: Undefined offset: 1 in /path/to/currency_converter.php on line 21

    This happened with the usual cron-triggered execution at 8:30am this morning and is still happening when I try manually now (it’s now around noon).

    Will try again later in case it’s just a Google hiccup but you may want to try yourself to see if you get the same results or whether it’s just busted for my deployment. :)

    Thanks again for writing this script in the first place, has kept my bosses happy for a long time so far!

    — 1337ingDisorder

  31. 1337ingDisorder
    1337ingDisorder at | | Reply

    Cancel my last post, the currency conversion is actually working fine. Our problem is that a different script (based on Apple reports, which have changed their format) started passing bad variables to the currency converter.

    Sorry for the false alarm and thanks again for this handy script! :)

    — 1337ingDisorder

  32. Gamlastan
    Gamlastan at | | Reply

    Hi, thanks for this, it was very useful!! I was using an external currency converter calculator from http://currencycrab.com which was ok.. but this way i will keep it cleaner.. cheers! :)

Leave a Reply