I'm trying to make a page that displays japanese characters. These japanese characters are stored in my database. I've done my research and tried many of the suggestions given but my japanese characters still return as question marks. Currently, this is how my code looks:
<?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>
I've already checked if my character encoding works and it does work if I replace $title_str[0] to japanese string. Am I missing something here? I'm not sure why the encoding works on strings I manually input but not the one I got from the database.
If from_encoding is not specified, the internal encoding will be used.from PHP.org on mb_convert_encoding. I guess this is probably what you intended, but try specifying it exactly as in the database (Pick one of these and chuck it in the final optional argument of mb_convert_encoding php.net/manual/en/mbstring.supported-encodings.php). I'm guessing the ?s are from mb_convert_encoding being unable to decypher the input to UTF-8