1

I have tried for a while now to set the right encoding to show danish characters on my MySQL query. I haven't found exactly a similar situation.

My output shows a question mark instead of the appropriate characters. This is my connect file.

<?php 
$con=mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}   
?>

And here is my display file:

<?php
include("connect.php");
mysql_select_db("paradise",$con);
$result=mysql_query("SELECT * FROM CITATER4 ORDER BY RAND() LIMIT 1",$con);

while($data = mysql_fetch_row($result))
{   
echo "<aside class=\"citatout\">";
echo "<div id=\"paradiso\" class=\"text-vertical-center-q\">";
echo utf8_encode("<h1 class=\"animated fadeIn\" align=center>$data[0]</h1>");
echo utf8_encode("<h2 class=\"animated fadeIn\" align=center>$data[1]</h2>");
echo "</div>";
echo "</aside>";
}
?>

I tried to set the encoding using this code but it still didn't change. I found this in another question here on Stackoverflow.

mysql_set_charset("utf8", $con);

I encoded the strings in the displayed file with utf8_encode and it still doesn't work.

Do you have a solution?

kristofferandreasen
  • 847
  • 2
  • 12
  • 24
  • We have a wonderful [utf8 checklist](http://stackoverflow.com/a/279279/989121), make sure you've completed all the steps. – georg Jan 20 '15 at 11:23

1 Answers1

1

You should not be needing to use utf8_encode.

Are your database tables utf8_danish_ci?

Try running this mysql query in e.g. phpmyadmin.

ALTER TABLE CITATER4 CONVERT TO CHARACTER SET utf8 COLLATE utf8_danish_ci;

Does HTML5 have <meta charset="utf-8"> in the head tag?

Petter Kjelkenes
  • 1,605
  • 1
  • 19
  • 25