0

I have a PHP file encoded with UTF-8 like this :

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

And before using sql request, I've added this line :

mysql_query("SET NAMES 'utf8'");

My database is coded in UTF-8 and varchar column with latin_swedish_ci

The result is like this picture :

enter image description here

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95

4 Answers4

0

Chang code to this

mysql_query("SET NAMES UTF8");

Save file like this

Save file like this

0

This is due to incorrect collation / charset of your column. Even if your database characted set is UTF-8, the column's character set takes precedence. To handle special characters like japanese chinese you column should be set to utf8_bin instead of latin_swedish_ci

0

Some Steps to Follow:

Meta tag for UTF8.

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

Set your PHP to use UTF8.

mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');

For MySql, you've to convert your table to UTF8.

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci

Also run:

 SET NAMES UTF8

as the first query after establishing a connection which will convert your DB connection to UTF8.

Jenson M John
  • 5,499
  • 5
  • 30
  • 46
0

html encoding in meta tag gets ignored if it is sent via http headers already.

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

Check from you browser what it thinks the current page encoding is:

  • Chrome: Tools - Encoding
  • Firefox: View - Character encoding

MySQL should be ok with just "set names utf8", table dada is encoded automatically to the mysql connections encoding

Imre L
  • 6,159
  • 24
  • 32