0

I am trying to display text using PHP from a database that is stored as latin_swedish_ci. It is a legacy system and I am refraining from changing it to utf-8. When the text is shown on the web page, some characters, which I think are quotes, shows as a question mark in a diamond �.

Most suggestions recommend changing the database to utf-8 but I prefer not to do this as I am not sure if it will break the rest of the system. I have also tried to change the html meta from <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> to <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> but it does not work.

The closest solution I tried is from this link PHP How to Remove/Replace Unknown question mark diamond characters but it will just replace the special character with nothing, but I want to retrieve the original character. Or at most, convert the quote to another quote that can be displayed on the web page.

To summarise, I need to display characters which shows up as question mark in a diamond in their original and intended characters.

Will appreciate any help on this, as I have been spending about 2 days on this and have found no solution.

claris
  • 11
  • 2
  • 1
    Database encoding and application encoding don't need to match. It's not clear whether you were assuming that or you actually have corrupt data you want to keep. (BTW, setting `` always comes as main tip but it's actually the most irrelevant step.) – Álvaro González Dec 26 '18 at 07:46
  • 1
    The only proper way is to first ensure that it fix the broken charset in your code, meaning that all parts of your code uses the same charset. This won't magically fix the broken data, but it'll ensure that new data is not broken. Then, if the data is with the incorrect charset in the database too, the old, broken data must be updated or reinserted. `latin_swedish_ci` is not a charset, it's a collation. – Qirel Dec 26 '18 at 07:49
  • Yes, the data is probably corrupted in the database. So in that case there's no way to retrieve the original characters. Thanks for the info about the meta tag and about latin_swedish_ci not being a charset. – claris Dec 26 '18 at 08:02
  • Possible approach can be executing 'set names binary' in mysql php connection session before doing selects. Then you can convert selected data with php's iconv functions (http://php.net/manual/en/function.iconv.php) from DB data charset to charset of web page. – Yuri Lachin Dec 26 '18 at 11:58
  • Thanks everyone for your replies, I will take it that the data is not retrievable and will omit displaying them. – claris Jan 05 '19 at 13:57

0 Answers0