I want to use utf 8 right now , but all my data is latin1 , what is the efficient way to convert data . Also I know how to change database’s structure(charset) to utf8 , What I want to do is changing charset of existing data .
update
Here are my old setting ,
- Html output : utf8
- Html input : utf8
- Php – mysql connection : latin1
- mysql (fields and tables) : latin1
Here are my new settings , and I hope this is the best way to create multi-language website
- Html output : utf8
- Html input : utf8
- Php – mysql connection : utf8
- sql (fields and tables) : utf8
If you apply utf8_encode() to an already UTF8 string it will return a garbled UTF8 output.
I made a function that addresses all this issues. It´s called forceUTF8().
You dont need to know what the encoding of your strings is. It can be Latin1 (iso 8859-1) or UTF8, or the string can have a mix of the two. forceUTF8() will convert everything to UTF8.
I did it because a service was giving me a feed of data all messed up, mixing UTF8 and Latin1 in the same string.
Usage:
I’ve included another function, fixUFT8(), wich will fix every UTF8 string that looks garbled.
Usage:
Examples:
will output:
Update: I converted theese into a static class, and they live in Github now:
https://github.com/neitanod/forceutf8