I’m using Google’s currency API to fetch exchange rates and store them in my database, but I ran into some problems. Here’s what I’m working with:
http://www.google.com/ig/calculator?hl=en&q=100USD=?GBP
I’m always passing 1USD as the first parameter and exchange that to all the currencies in my database, cast the result variable as a float and store it. Everything works fine until the result from the API is greater than 1000. For example:
http://www.google.com/ig/calculator?hl=en&q=100USD=?PYG
This returns “440 528.634” as the value, and the problem is in the space delimiter. When I cast that to a float it only stores “440”. I tried running str_replace() on it before i cast it to a float, but for some reason that doesn’t work – I’m guessing it’s not a regular whitespace but a special character of some sort. I also tried exploding the variable by a space and returning the merged array fields, but no dice. I’m running out of ideas here so I really hope someone can help me on this 😀
Its a non-breaking space character. You can replace it if you refer to it as
\xA0:Note the double quotes. Use those instead of single quotes as it won’t work correctly otherwise.