I had to try to “fix” several broken UTF8 situations in the past, and, unfortunately, it was never easy and often quite impossible.
If you cannot determine exactly how it was broken, and it was always broken in the same way, then it will be difficult to “cancel” the damage.
If you want to try to undo the damage, it is best to start writing sample code where you make numerous variants of mb_convert_encoding () calls to find out if you can find a combination of "from" and "from", to ', which captures your data. In the end, it is often better not to even bother about fixing old data due to pain levels, but instead just fix the situation in the future.
However, before doing this, you need to make sure that you fix everything that causes this problem in the first place. You already mentioned that sorting and database table editors are installed correctly. But there are still places where you need to check that everything is correct UTF-8:
- Make sure you serve your HTML as UTF-8:
- header ("Content-Type: text / html; charset = utf-8");
- Change your default PHP encoding to utf-8:
- ini_set ("default_charset", 'utf-8');
- If your database does not ALWAYS talk in utf-8, you may need to talk about it in each connection in order to provide it in utf-8 mode, in MySQL you do this by issuing:
- You may need to say that your web server is always trying to talk in UTF8, in Apache this command:
- Finally, you need to ALWAYS make sure that you are using PHP functions that are the correct complaint of UTF-8. This means that always use the mb_ * string functions in the multibyte style. This also means that when calling functions such as htmlspecialchars (), you include the appropriate “utf-8” charset parameter at the end to make sure that it does not encode them incorrectly.
If you skip any one step through the whole process, the encoding may be distorted and problems arise. As soon as you get into the “groove” for utf-8, all this becomes second nature. And, of course, PHP6 should be a completely one-time complaint from getgo, which will make a lot of this easier (hopefully)
Eli Aug 28 '09 at 17:59 2009-08-28 17:59
source share