0

I have a simple function to display genman texts from database. I get bad output on HTML : That's the output in HTML (you can see wei� instead of weiß) enter image description here

My HTML head :

<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="latin1">

I tried UTF-8, ISO-8859-1 didn't work as well, same bad character

The data in my PHPMyQdmin table looks fine: enter image description here

This is the structure of my table (field cName):

enter image description here

UPDATE 1 I tried to force the encoding in the SELECT query but didn't get the right result too :

SELECT column1, CONVERT(column2 USING utf8)
FROM my_table 
WHERE my_condition;

UPDATE 2 this is my PDO connection :

$conn = new PDO("mysql:host=$servername;dbname=cmondo;charset=utf8", $username, $password);
  • Why are you using `latin1_swedish_ci` encoding for UTF8 German symbols? – Peon May 31 '17 at 11:24
  • yes, you can see the table structure picture – ali chouchen May 31 '17 at 11:25
  • `latin1_swedish_ci` is wrong for UTF8 German symbols you should use `uft8_general_ci` or `utf8_bin` – Raymond Nijland May 31 '17 at 11:28
  • I changed it in my table but I still get the same HTML output – ali chouchen May 31 '17 at 11:32
  • [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze May 31 '17 at 12:36
  • FWIW, `latin1_swedish_ci` is the ***collation***, meaning text will be sorted by Swedish dictionary rules when sorted and such; largely that doesn't have any influence on anything. The `latin1` part denotes the encoding, and `latin1` can perfectly store German characters. Everyone getting upset about the "swedish" part here is on the wrong track entirely. The crux of the matter is, as in 99% of all such question, the ***connection encoding*** set in your PDO connection. – deceze May 31 '17 at 12:38
  • See my update, my PDO connection uses utf8 – ali chouchen May 31 '17 at 12:42

1 Answers1

-1

Currently you are using latin1_swedish_ci. You have to use either utf-8-general-ci or utf-8-unicode-ci.

To know the difference : UTF-8: General? Bin? Unicode?

Also add the following in your file

<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">

and check which encoding your web server sends in the header.

If you use PHP, you can send your own headers in this way (you have to put this before any other output):

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

Also check that you saved your file in UTF-8 format.

Sehdev
  • 5,486
  • 3
  • 11
  • 34