PHP,sql, UTF-8 encoding

2019-07-18 03:27发布

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.

2条回答
SAY GOODBYE
2楼-- · 2019-07-18 04:05

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.

查看更多
爷、活的狠高调
3楼-- · 2019-07-18 04:26

$db = mysql_connect(...);

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

Simples!

查看更多
登录 后发表回答