How to display Germany Umlauts (ü, ä, ö) from sql to Php?

I try to display this German character correctly if I do not use htmlentities() , the output is unabh ngig , but when I try to use htmlentities() this word is missing, why?

 <?php $str = htmlentities("unabhängig"); ?> <!DOCTYPE html> <html lang="en"> <head> <title>Test</title> <meta charset='utf-8'> </head> <body> </body> <div><?php echo $str;?></div> 
+4
source share
4 answers

I had the same problem with ü, ä etc.

Immediately after selecting the database, I implemented two lines:

 mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET 'utf8'"); 

as suggested here: http://www.flashhilfe.de/forum/serverseitige-programmierung/php-mysql-wie-utf-8-beim-connect-festlegen-225225-225225.html

Best, Yannis

+6
source

You should simply be able to send ü without encoding separately, ensuring that the encoding is set to utf-8 using an HTTP header.

If for some reason you cannot do this, use:

 Ü = &Uuml; 

or

 ü = &uuml; 
0
source

This is the format for encoding:

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

Make sure your encoding is not forcibly linked to htaccess or apache. check that the selected encoding is in your browser when you browse the site, if it is not utf-8, then it is forced. If forced you can add this to htaccess

 AddDefaultCharset UTF-8 

Make sure the database table is in utf-8

Make sure your connection to your database is in utf-8 http://php.net/manual/en/function.mysql-set-charset.php

 mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn); 

You can pass UTF-8 encoding to htmlentities to use the correct encoding. or you can use htmlspecialchars http://php.net/manual/en/function.htmlentities.php

0
source

And if you don’t want to worry about so many different encodings or if htmlentities doesn’t work for you, here is an alternative: I used the mysqli DB connection (and PHPV5) form message for writing / pasting to MySQl DB.

 $Notes = $_POST['Notes']; //can be text input or textarea. $Notes = str_replace('"', '&quot;', $Notes); //double quotes for mailto: emails. $von = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é"); //to correct double whitepaces as well $zu = array("&auml;","&ouml;","&uuml;","&szlig;","&Auml;","&Ouml;","&Uuml;","&nbsp;","&#233;"); $Notes = str_replace($von, $zu, $Notes); echo " Notes:".$Notes."<br>" ; $Notes = mysqli_real_escape_string($link, $Notes); //for recommended mysqli DB connection. //$Notes = mysql_real_escape_string($Notes); //for old deprecated mysql DB connection. // mysqli_real_escape_string Escapes special characters in a string for use in an SQL statement echo " Notes:".$Notes ; //ready for inserting enter code here //Optional: $charset = mysqli_character_set_name($link); //only works for mysqli DB connection printf ("To check your character set but not necessary %s\n",$charset); 
0
source

All Articles