phpcurrencyeuro

Is there easy way to convert currency with php?


I was thinking is there any easy solution to convert euro prices to dollars with PHP. Something similar to date and time function maybe.

edit. I have euro prices on the site but I'd like to have dollar prices along them too. So I need solution to auto calc dollars in real time.


Solution

  • You will need to use a 3-rd party api to do this conversion for you. Please take a look at this one, for example: http://fixer.io/ . Not to reinvent the wheel, I recommend you using a ready-made wrapper for actually making the requests. I've found this one which looks pretty thin and solid: https://github.com/fadion/Fixerio

    Then, all you have to do is something like that:

    $exchange = new Exchange();
    $exchange->base(Currency::USD);
    $exchange->symbols(Currency::EUR, Currency::GBP);
    
    $rates = $exchange->get();