1

I have some special characters for values coming from database like æ and Ø. When I inspect the database using phpmyadmin on both XAMPP and online, this is how it appears:

enter image description here

But in the processed PHP page, it appears fine locally, but not on the server. So basically, there is some problem on the online version which is preventing these values from being displayed properly.

I already have this in my head portion:

<meta http-equiv="content-type" content="text/html;charset=UTF-8" />

And in my .htaccess file:

AddDefaultCharset UTF-8
DefaultLanguage en-US

Collation is latin1_swedish_ci for the database, I tried switching it to utf-8 and that didn't help.

Inception
  • 455
  • 1
  • 9
  • 32
  • In your php file use: header('Content-Type: text/html; charset=utf-8'); in mysql change - collation-server=UTF-8_general_ci – Tom Jul 05 '18 at 06:45
  • @Tom I have tried the above and it's still the same. One question, now the database collation is changed to UTF-8_general_ci, but the tables are still in latin1_swedish_ci, should I change them as well? – Inception Jul 05 '18 at 06:58
  • @Tom Changed every table to utf-8, still didn't fix it... – Inception Jul 05 '18 at 07:22
  • https://www.toptal.com/php/a-utf-8-primer-for-php-and-mysql – Tom Jul 05 '18 at 07:32
  • @Tom - Did you change the _columns_ to utf8 (or utf8mb4)? What about the connection parameters? – Rick James Jul 05 '18 at 16:34
  • after having changed everywhere to UTF8 (which is the right thing to do), ensure that your database connection is also utf8, do this right after `mysqli_connect` : `mysqli_set_charset($this->connection,"utf8");` (adapt to PDO or the $this object accordingly) – Thomas G Jul 05 '18 at 16:53

1 Answers1

0

That is "Mojibake", wherein, for example, a 2-byte UTF-8 character

If I am not mistaken your examples disagree with the text. The following utf8 char maps to the matching 2-char pair when missmapped through latin1.

ü  ü
ö  ö
Ø  Ø
æ  Ã¦

For more about the causes and cures: Trouble with UTF-8 characters; what I see is not what I stored

Rick James
  • 135,179
  • 13
  • 127
  • 222