2

I am writing a web application where I have to display some german special characters like ä,ü,ö.

I am using utf_general_ci encode in mysql to store the data. So, the special characters like Ü is stored as ü, hence when I fetch the data that contains a character like Ü is displayed as ü. which encoding should be used in html to display the german characters properly in html page?

I have used UTF-8 encoding as well as iso-8859-1 both does not seem to work.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta charset="UTF-8">

any help is appreciated thanks in advance

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80
Sagar
  • 33
  • 6
  • UTF-8 is correct. You also need to set the database connection's encoding to UTF-8, that is the most common reason for the thing happening that you describe – Pekka Aug 31 '16 at 08:57
  • but there is no option of UTF-8 in database settings – Sagar Aug 31 '16 at 09:10
  • No, the connection itself. http://stackoverflow.com/questions/279170/how-to-support-utf-8-completely-in-a-web-application – Pekka Aug 31 '16 at 09:12
  • ok thank you I will try that – Sagar Aug 31 '16 at 09:25
  • I already have few data in database which are utf_general_ci encoded for german letters ex. (ü for Ü) can't this data be converted back to Ü in html ?? – Sagar Aug 31 '16 at 13:04
  • So you fixed the connection and the characters are in there the wrong way? You can see it wrong when viewing the database through phpmyadmin and similar? – Pekka Aug 31 '16 at 13:08
  • The main problem is I already have few data that were utf_general_ci encoded these data is still displayed like ü for Ü in my html page. Using UTF-8 new set of data is stored properly but the problem is with the old data – Sagar Aug 31 '16 at 13:25
  • Yeah, see e.g. http://stackoverflow.com/questions/1344692/i-need-help-fixing-broken-utf8-encoding – Pekka Aug 31 '16 at 15:17
  • Often, a manual `REPLACE()` operation in the database is the easiest way to go, especially when the range of affected characters is from one alphabet only (ÄäÖöÜüß for German e.g. and maybe the occasional á é í) – Pekka Aug 31 '16 at 15:18
  • thanks a lot for the comments..:) I will check with the replace function – Sagar Aug 31 '16 at 15:55

1 Answers1

0

I found the solution. The problem was, the data in database are saved using charset = latin1 and collation = latin1_german2_ci hence ü was encoded as ü, so in the web application framework I was using i just added these two lines

'charset'   => 'latin1',
'collation' => 'latin1_german2_ci',

and it worked. Just as a side note when the web application is encoding the data in using 'charset' => 'utf8' and 'collation' => 'utf8_unicode_ci' and some data is already present in the database which has used charset=latin1 and collation=latin1_german2_ci. This may create problem when you try to fetch data using php scripts because of two different encoding present.

Sagar
  • 33
  • 6