1

In the MySQL documentation the string function REPLACE() is said to be "multi-byte safe". I have problems working with my Russian charset.

    SELECT REPLACE('оофо', 'о', '*'); -- "**ф*", everything is correct
    SELECT REPLACE('оофоо', 'о', '*'); -- "**фоо", NOT CORRECT

Where should I look for the source of the problem?

Additional information:

OS - Windows 7 (Russian),
SELECT CHARSET('оофоо'); -- "utf8",
SELECT LENGTH('оофоо'); -- "6".
homework
  • 4,987
  • 11
  • 40
  • 50
mosceo
  • 1,222
  • 11
  • 26
  • `SELECT LENGTH('оофоо')` returns **10** for me, and your both `REPLACE` calls return the right result. – inhan Aug 18 '12 at 22:50

1 Answers1

1
  1. Make sure the database charset/coallition is UTF-8

  2. On the page you insert these russian characters ( the form, textarea ), make sure the encoding is UTF-8, by setting Content-Type to text/html; charset=utf-8. Enter in Russian text directly to the form input.

  3. On the processing page that handles this form, which inserts it into the database, make sure to do SET NAMES utf8 so it's stored as UTF-8 before you insert the data, in a separate query beforehand.

  4. When you render the content from the database in a view, make sure the Content-Type is text/html; charset=utf-8.

  5. Make sure that the content-type is not windows-1251 or iso-8859-1/latin1. Make sure the database charset/coallition is NOT ISO-8859-1/Latin1.


Refer to, for further information: Fixing encodings

Community
  • 1
  • 1
homework
  • 4,987
  • 11
  • 40
  • 50