1

There are the problems of data in mysql.

Some data store with the string like (1):"hello & hello ' hello è ...". And some data store with the string like (2):"hello à hello é hello ê ...".

I can solve the string (1) to the normal string, but I don't know how to convert the string (2) to the normal string?

Note : We can not change the data in the existing database :/ Also the both sample is store in the same table and the charset of the table is latin1!

Kannika
  • 2,538
  • 2
  • 27
  • 38

3 Answers3

3

hello à hello é hello ê probably is UTF-8 interpreted as ISO-8859-1.

You can either change the interpretation, e.g. in a browser set a charset, or convert it to ISO-8859-1 using utf8_decode().

AndreKR
  • 32,613
  • 18
  • 106
  • 168
  • why this character "Ã" is not converted ? – Kannika Oct 22 '12 at 04:24
  • all character é,ê,... is converted, except this one "Ã"! you know why? – Kannika Oct 22 '12 at 04:30
  • I can't imagine what letter that might have been. In UTF-8 an à (0xC3) is always followed by a second byte to form a character. à (0xC3 0x20) is an invalid UTF-8 sequence. – AndreKR Oct 22 '12 at 04:36
  • it's just this character that cannot convert. So i just change it from "Ã" to "à" by using str_replace() :D thanks for help @AndreKR – Kannika Oct 22 '12 at 04:41
  • 1
    Oh, I see. `à` in UTF-8 is `0xC3 0xA0`. `A0` in ISO 8859-1 is the non-breakable space which easily breaks when being copied and pasted for example. – AndreKR Oct 22 '12 at 04:46
0

EDIT-

Without changing the DB structure try this --

ini_set('default_charset', 'YOUR_CHARACTER_SET')

OR try this --

header('Content-Type: text/html; charset=iso-8859-1');

Check this setting, its all bcoz of table collation

enter image description here

swapnesh
  • 26,318
  • 22
  • 94
  • 126
  • That alone wouldn't help because the data would be converted to UTF-8 *again*. He would have to convert it with something like CONVERT(CAST(... as BINARY) USING ...) but he wrote he cannot change the data in the DB. – AndreKR Oct 22 '12 at 04:21
  • @AndreKR yeah just checked in and thx for the info i updated my answer i think this will help him or using header() too may help him in this case – swapnesh Oct 22 '12 at 04:24
  • @swapnesh both solution is not my case, because 1. i can not change the database. 2. i'm convert the text to the image. so no need to put the header. anyway, thanks for helping me :) – Kannika Oct 22 '12 at 04:32
0

Use CONVERT as CONVERT ("hello à hello é hello ê ...", ascii) ....

Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73