[英]Character encoding issue in PHP and MySQL
When I run a query directly in MySQL using phpMyAdmin it allows –
(long dash, not normal -
), but when I run this query from my PHP code, it turns them to –
. 当我在MySQL使用phpMyAdmin直接运行一个查询它允许
–
长划线,不正常-
但是当我从我的PHP代码运行此查询,原来他们–
。
If you encode – it'll come %E2%80%93
(in JavaScript). 如果您进行编码–将会出现
%E2%80%93
(在JavaScript中)。 %E2
becomes â
, %80
becomes €
and %93
becomes “
. %E2
变成â
, %80
变成€
, %93
变成“
。 I don't understand when I run the query in phpMyAdmin it saves data as –
, but when I run the query in my PHP code, then it does not work in the way I want. 我不明白何时在phpMyAdmin中运行查询时,它会将数据另存为
–
,但是当我在PHP代码中运行查询时,则它无法按我想要的方式工作。
Which character encoding do you use in your table? 您在表格中使用哪种字符编码? After connecting to the DB in php try to run this:
连接到php中的数据库后,尝试运行此命令:
mysql_query('SET NAMES utf8'); //if you use utf-8
也许phpMyAdmin引擎将长破折号转义为普通破折号?
Probably you are missing to put the met tag on your HTML, have you write the next line in the head of your HTML document? 可能是您缺少在HTML上放置met标签,您是否在HTML文档的开头写了下一行?
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
Otherwise, the browser interprets it as ISO-8859-1. 否则,浏览器会将其解释为ISO-8859-1。
You should use the same encoding everywhere, on your database, on your connection and on your html document. 您应该在数据库,连接和html文档的任何地方都使用相同的编码。
For ensure you have a utf-8 table, run the next statement, and check it says CHARSET=utf8 almost at the end. 为了确保您拥有utf-8表,请运行下一条语句,并检查它几乎在末尾显示CHARSET = utf8 。
SHOW CREATE TABLE tableName;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.