Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to display this German character the proper way, if I don't use htmlentities() the output is unabh�ngig, but when I try to use htmlentities() the word is missing, why is that?

<?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>
like image 817
Leandro Garcia Avatar asked Jul 11 '12 11:07

Leandro Garcia


1 Answers

I had the same problem with the ü, ä, etc.

Right after selecting the database I implemented this 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

like image 81
Yannis Avatar answered Sep 29 '22 11:09

Yannis