0

Am using mysql and php.

In my database i have column value like following.

Preaqueça o forno médio (180ºC).

But when i retrieve it using php it shows below string.

Preaqueu00e7a o forno mu00e9dio (180u00baC).

Something is wrong with character encoding. Any ideas to fix it?

jomin v george
  • 1,299
  • 11
  • 26

2 Answers2

0

You seem to have two problems.

ç is Mojibake for ç and º is Mojibake for º. For that, you need to check:

visible.)

  • The bytes to be stored need to be UTF-8-encoded. Fix this.
  • The connection when INSERTing and SELECTing text needs to specify utf8 or utf8mb4. Fix this.
  • The column needs to be declared CHARACTER SET utf8 (or utf8mb4). Fix this.
  • HTML should start with .

Hex 00e7 looks like the "Unicode codepoint" for ç, but it is unclear how you could have created that.

Let's start by doing SELECT col, HEX(col) FROM ... to see what got stored. Also provide SHOW CREATE TABLE. (More details in Test the data .)

After fixing the Mojibake issues and doing the HEX, start a new question. (I fear that this thread will get too messy to keep.)

Community
  • 1
  • 1
Rick James
  • 135,179
  • 13
  • 127
  • 222
0

I was using json_encode to display the output from select query. That was causing the problem.

function my_json_encode($arr)
{
        //convmap since 0x80 char codes so it takes all multibyte codes (above ASCII 127). So such characters are being "hidden" from normal json_encoding
        array_walk_recursive($arr, function (&$item, $key) { if (is_string($item)) $item = mb_encode_numericentity($item, array (0x80, 0xffff, 0, 0xffff), 'UTF-8'); });
        return mb_decode_numericentity(json_encode($arr), array (0x80, 0xffff, 0, 0xffff), 'UTF-8');

}

Used this function instead of the default json_encode.And it works perfectly.

jomin v george
  • 1,299
  • 11
  • 26