2

I am trying to understand some problem at the UTF-8 encoding at the forum i am building, For start, I am using:

    <?xml version="1.0" encoding="utf-8"?>

and:

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

So the xml encoding is utf-8 and same is for the meta charset, also the files i am working with is UTF-8 and inside the Notepad++ it is UTF-8 without BOM, at the sql server the database and the tables are utf8_general_ci,

The problem is when i am inserting the data from the php code i see the data ok at the browser but weird at the sql server,

when i inserting the data from the sql server i see the data ok at the sql server but weird at the browser, If anyone know something please i will be very thankful.

Aviel Fedida
  • 4,004
  • 9
  • 54
  • 88
  • 2
    Have you `SET NAMES 'utf8'` ? You can do this with `mysql_set_charset("utf8")` or `$db->set_charset("utf8")` before making any queries – Esailija Aug 05 '12 at 12:18
  • use this in php `header('Content-Type: text/html; charset=utf-8');` plus adding @Esailija query after connection directly, assuming you are using mysql – Hawili Aug 05 '12 at 12:19
  • Thank you i shoulded set the charset at the connection same is here: http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names – Aviel Fedida Aug 05 '12 at 12:36

2 Answers2

1

What kind of sql server do you use? I case of postgres or mysql, you should define the tables and or the fields as utf-8 aware.

Otherwise, when the db was filled via csv and the data inside are not utf-8 encoded, the result on your pages will be then also not utf-8 encoded.

In that case, you can transform the characterset manually.

devanand
  • 5,116
  • 2
  • 20
  • 19
1

$db = mysql_connect(...);

/* change character set to utf8 */ mysql_query('SET NAMES utf8 ');

Simples!

alexjosesilva
  • 139
  • 1
  • 7