0

I have the following UTF-8 data in my database:

ãダンヒル

In japanese:

ダンヒル

The field and the database are set to utf_8_general_ci. I can't figure out how to display the proper japanese characters in my html. Here's what I did so far with no success:

<?php
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
header('Content-Type: text/html; charset=UTF-8');
?>

Also, in my html header, I set the charset to utf-8:

<meta charset="UTF-8">

Database connection is mysqli, set_charset is set to utf-8.

Note that using this tool, I managed to encode my string to the proper japense characters.

Any help, would be appreciated, thanks!

acanana
  • 51
  • 7
  • I'd guess your DB connection isn't set to UTF8. You have `ãダンヒル` in the DB or `ダンヒル`? – chris85 Aug 03 '17 at 15:52
  • I have `ãダンヒル`. – acanana Aug 03 '17 at 15:53
  • Okay so when you inserted it wasn't set as UTF8 you're going to need to re-insert the data as well. Can you please add the DB connection you are using to the question? – chris85 Aug 03 '17 at 15:53
  • Ok, I'll try this. I inherited a 17 years old database today. Thank you! – acanana Aug 03 '17 at 15:55

1 Answers1

0

Try to add the header:

header('Content-Type: text/html; charset=utf-8');

at the beginning of your code.

OR,

MySql:

Try to set charachter encoding after mysql_connect function like this:

mysql_query ("set character_set_client='utf8'"); 
mysql_query ("set character_set_results='utf8'"); 

mysql_query ("set collation_connection='utf8_general_ci'"); 

Mysqli:

 $mysqli = new mysqli("localhost", "my_user", "my_password", "test");

 /* check connection */
  if (mysqli_connect_errno()) {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
  }

  /* change character set to utf8 */
  if (!$mysqli->set_charset("utf8")) {
      printf("Error loading character set utf8: %s\n", $mysqli->error);
  } else {
      printf("Current character set: %s\n", $mysqli->character_set_name());
  }

  $mysqli->close();
Chandra Kumar
  • 4,127
  • 1
  • 17
  • 25