0

For some weeks I keep googling for solutions to a problem with my Webserver.

For some reason (still have no clue why), characters from a MySQL DB, "Ș", "Ț" & "Ă" is parsing to my PHP webpage as "?" and "Î", "Â" is parsing as the diamond question mark. DB charset is UTF8, PHP page header is UTF8. I tried iso8859-2 (Eastern European Charset), the diamond question mark disappears and "Î" and "Â" take its place, but the other ones does not change at all, still a question mark appears instead of the original Character. DB CHARSET = utf8 TBL COLLATION = utf8-romanian-ci

Where am I doing wrong?

mysql> show variables like 'char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

HTML

<!doctype html>
<html>
<head>
<meta charset="utf-8">

I'd appreciate any suggestion and/or guidance.

sealview
  • 99
  • 1
  • 8
  • 1
    possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – deceze Jan 06 '14 at 16:36

1 Answers1

0

Your error is that you are setting your meta charset=utf-8" which really isn't the same you need to set the page header with utf8 like this:

<?php header('Content-Type: text/html; charset=utf-8'); ?>

set this at the top of the page before you output any html or any php code

Liam Sorsby
  • 2,912
  • 3
  • 28
  • 51
  • Thank you for the reply. I did insert the header code, without any effect in return. It's odd to me, why I can see in phpMyAdmin all the characters in good shape, but not the same in the frontend PHP. – sealview Jan 06 '14 at 16:49
  • @sealview have you tried echo utf8_decode($text); or echo utf8_encode($text);? – Liam Sorsby Jan 06 '14 at 17:02
  • I just did. I believe my problem is much deeper, deeper within the Apache, MySQL and PHP. Now utf8_decode() returns "ÃŽ" instead of "Ă". I will deploy a new system with LAMP and test same scenario (different environment) with deafult CHARSETS. – sealview Jan 06 '14 at 17:20
  • I very much doubt it is a issue deeper in apache, MySQL or PHP as i had the very same issue in PHP with chinese characters. The issue would of more likely been that the encoding of the characters input into MySQL was not encoded using UTF-8. However the utf8_encode was a long shot as this will only encode ISO-8859-1 encoded strings to UTF8 however another long shot is you could echo out the output of mb_detect_encoding($text) however as it is very difficult to detect encoding types this is as i said a very long shot – Liam Sorsby Jan 06 '14 at 17:28