I like to convert string with a price to a float value. The price comes from different languages and countries and can look like this:
1,00 €
€ 1.00
1'000,00 EUR
1 000.00$
1,000.00$
1.000,00 EURO
or whatever you can think of…
Not sure I got the full range of possibilities with my examples. I am also not sure if it is possible to make in international convert blindly, maybe I have to use a language code? So for the start Euro and Dollar would be enough.
floatval() is kind of stupid so I need something more here. I think I should first remove all chars beside numbers, , and .. Then fix the , / . and use floatval finally.
Has someone done this before and can help me a little?
I would prefer a solution without regexp 😉
Update: Current solution with tests https://onlinephp.io/c/9e95e
Ok, I tried it myself. What do you think of this?
Here some tests: https://onlinephp.io/c/9e95e
Sorry. I couldn’t include the other functions because codepad did not like them. But I compared them and there was trouble with strings like "22 000,76" or "22.000"
Update: As Limitless isa pointed out you might have a look at the build in function money-format.