UTF-8 and German characters?

I have a problem with German characters on my website,

In the html / php part of the site, I have this code for installing utf-8:

<meta charset="utf-8"> 

in mysql, I have this code to install utf-8

 SET CHARSET 'utf8'; 
  • Here are a few words in German: Gemäß

  • This is how the word looks in the mysql table:

    Gem&Atilde;&curren;&Atilde;Ÿ

  • Here's how the word appears on the site: Gemäß

What is the problem? Thanks.

+7
source share
9 answers

First, make sure you have UTF-8 characters in your database.

After that, try using SET NAMES 'UTF8' after connecting to MySQL:

 $con=mysqli_connect("host", "user", "pw", "db"); if (!$con) { die('Failed to connect to mySQL: ' .mysqli_connect_errno()); } mysqli_query($con, "SET NAMES 'UTF8'") or die("ERROR: ". mysqli_error($con)); 

As the manual says:

SET NAMES indicates which character set the client will use to send SQL statements to the server ... It also indicates the character set that the server should use to send the results back to the client.

+1
source

I used this code to get the header:

 $title = mysql_real_escape_string(htmlentities($_POST['title'])); 

I just redefine it on

 $title = $_POST['title']; 
+1
source

Try SET NAMES 'utf8' or SET NAMES 'utf-8' . Some of these works are great for the Portuguese, perhaps German as well. I just can’t remember which one is correct, but if it’s not, an error will be generated.

0
source

you must make sure that CONNECTION is also utf-8.

with mysqli, this is done with something like this:

 $connection = mysqli_connect($host, $user, $pass, $db_name); $connection->set_charset("utf8"); 

Now, if you somehow ended up with the wrong characters in the database, there is a way to do it right:

  • in a PHP script, retrieve the information as it is now, i.e. without making a connection. Thus, the error will be inverted and fixed, and in your php file you will have characters in the correct utf-8 format.
  • in a PHP script, write back the information with setting up connection to utf-8
  • at this moment you should see the correct character in your database
  • now change all your read / write functions of your site to use utf-8 from now on
0
source

in HTML5 use

 <meta charset="utf-8"> 

in HTML 4.0.1 use

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
0
source

I had the same problem. which I solved with:

if you have already created your table, you need to change the character set as:

 alter table <table name> convert to character set utf8 collate utf8_general_ci. 

your table character set is set to latin_swedish by default.

You may also encounter some problems when retrieving data and displaying it on your page. To do this, include: mysql_set_charset('utf8') just below the line where you connected your database. eg:

 mysql_connect('localhost','root',''); mysql_select_db('my db'); mysql_set_charset('utf8'); 
0
source

the results are an html object encoded as if they were processed by htmlentities (), I wonder if your variables were taken from the received form or processed, for example, using the wysiwg editor?

In any case, they should print well on the html template, but html_entity_decode () should do it.

Hope this helps

0
source

You will need to do this for php 5.x

 $yourNiceLookingString = htmlspecialchars ($YourStringFromDB, ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'); 

and for php 4.x

  $yourNiceLookingString = htmlspecialchars($YourStringFromDB); 
0
source

Set the data type in your database and for using UTF-8, this should solve the problem.

0
source

All Articles