skip to Main Content

I have a database full of data looking like this ΑντικαταβολΠand I need to find a way to convert it all into proper, utf8 data.

Is there a way to do it? The db is MySQL and is from an oscommerce merchant v2.2 installation.

2

Answers


  1. First you need to figure out the original encoding, I suggest you get a text editor that allows “Load As (encoding)” like EmEditor, copy the text into a text file and open it as different encodings and see in which encoding it looks right. Then we can talk about how to convert that to UTF-8.


    UPDATE: I just checked your dump file, copying a small portion of the weird looking text into a text file, saving as binary and reopening as UTF-8 shows up as proper Greek, have a php page like this:

    <html>
    <head>
         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body>
    <?php
    $res = mysql_query( 'SELECT BINARY first_name FROM address_book LIMIT 5' );
    while( $r = mysql_fetch_row( $res ) ) {
        echo $r[0].'<br />';
    }
    ?>
    </body>
    </html>
    

    see what you get.

    Login or Signup to reply.
  2. First of all I’d try to identify what the character set of the data is. To do this:

    • use SHOW CREATE TABLE to find out the collation of the MySQL table that has the data in
    • set your client to use the same collation (this ensures that no translation is peformed)
    • export the table with mysqldump to a file on the server

    Now you’ve got a copy of the data from the table that’s un-altered and byte for byte the same as what’s stored in the database. Using your favourite text editor try to switch character set encodings and work out what character set the data is stored in. When you eventually set the correct character set in your browser the text will render correctly.

    Likely candidates for the encoding will be ISO-8859-7 or UTF-8.

    Once you’ve identified the correct encoding you should be able to modify the charset encoding in the mysqldump file and then load this data correctly into a new table.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search