我正在试着制作一个显示日文字符的页面。这些日文字符存储在我的数据库中。我已经完成了我的研究并尝试了很多建议,但是我的日语角色仍然作为问号返回。目前,这是我的代码的外观:在PHP页面上显示来自MySql数据库的日文字符
<?php
$con=mysqli_connect("host", "user", "pw", "db");
if (!$con)
{
die('Failed to connect to mySQL: ' .mysqli_connect_errno());
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
mb_internal_encoding('UTF-8'); ?>
<center>
<div id="fb-root"></div>
<form method="POST" id="myForm">
<h1>
<?php
$title = mysqli_query($con, "SELECT `title` FROM titles WHERE c1='a' or c2 ='b'") or die("ERROR: ". mysqli_error($con));
$title_str = mysqli_fetch_array($title);
$mystr = mb_convert_encoding($title_str[0], "UTF-8");
echo "test: ".$mystr;
?>
</h1><br/>
</form>
</body>
如果我的字符编码的作品,如果我更换$ title_str [0]日本串它的工作我已经检查。我在这里错过了什么吗?我不知道为什么编码在字符串手动输入,但不是我从数据库中获得的字符串。
你确定数据库中字符串的字段能够保存UTF8吗? – AStupidNoob
是的。我的数据库中的所有字符串都是日语字符 – user1597438
'如果未指定from_encoding,则将使用mb_convert_encoding上PHP.org的内部编码。我想这可能是你想要的,但请尝试完全按照在数据库中指定它(选择其中的一个并在mb_convert_encoding http://www.php.net/manual/en/mbstring.supported的最终可选参数中查找它-encodings.php)。我猜测是从mb_convert_encoding无法将输入分辨率转换为UTF-8 – AStupidNoob