Displaying Japanese characters from MySql database on PHP page -


i'm trying make page displays japanese characters. these japanese characters stored in database. i've done research , tried many of suggestions given japanese characters still return question marks. currently, how code looks:

<?php    $con=mysqli_connect("host", "user", "pw", "db");    if (!$con) {     die('failed connect 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` titles 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 checked if character encoding works , work if replace $title_str[0] japanese string. missing here? i'm not sure why encoding works on strings manually input not 1 got database.

try using set names utf8 after connecting mysql:

$con=mysqli_connect("host", "user", "pw", "db");    if (!$con) {     die('failed connect mysql: ' .mysqli_connect_errno()); }  mysqli_query($con, "set names 'utf8'") or die("error: ". mysqli_error($con)); 

as manual says:

set names indicates character set client use send sql statements server... specifies character set server should use sending results client.

after there no need use mb_convert_encoding.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -