0

The problem is that I have latin1 charset in db. The default output is utf-8 in php. even when i am using php iconv, it returns null as the new string is supposedly already utf-8.

Converting DB would need downtime.

I cant use json_encode because the string is malformed utf-8 containing �.

I need an alternative to temporarily fix the issue without having to migrate the db.

I need to transfer the associative array back to JS. I am using Ajax for getting the data.

jainarpitr
  • 15
  • 4

2 Answers2

0

You could convert the encoding, prior to passing the data on to json_encode (which really needs UTF8 encoded strings). Using the mb_convert_encoding function will do:

$utf8String = mb_convert_encoding(
    $sourceString,
    'UTF8',
    '<src encoding>' //in your case: ISO-8859-1
);

Meanwhile, work out a strategy of how you are going to convert your DB to UTF-8, because it'll save you a lot of pain endlessly juggling different encodings throughout your project.

Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
0

Set your driver's encoding (client) explicitely to UTF-8.

Examples with:

Community
  • 1
  • 1
RandomSeed
  • 29,301
  • 6
  • 52
  • 87