Reputation: 897
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?
Upvotes: 1
Views: 1603
Reputation: 1625
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?
Upvotes: 1