在 MySQL 数据库中保存口音
我正在尝试将法语口音保存在我的数据库中,但它们并没有像在数据库中那样保存.
例如,é"被保存为é".
我尝试将我的文件设置为Unicode (utf-8)",数据库中的字段是utf8_general_ci"以及数据库本身.
当我查看发布的数据时通过带有 Firebug 的 AJAX,我看到重音以é"的形式传递,所以它是正确的.
谢谢,让我知道您需要更多信息!
I'm trying to save French accents in my database, but they aren't saved like they should in the DB.
For example, a "é" is saved as "é".
I've tried to set my files to "Unicode (utf-8)", the fields in the DB are "utf8_general_ci" as well as the DB itself.
When I look at my data posted through AJAX with Firebug, I see the accent passed as "é", so it's correct.
Thanks and let me know you need more info!
推荐答案
我个人解决了同样的问题,在MySQL连接代码之后添加:
Personally I solved the same issue by adding after the MySQL connection code:
mysql_set_charset("utf8");
或用于 mysqli:
or for mysqli:
mysqli_set_charset($conn, "utf8");
或 mysqli OOP 等价物:
or the mysqli OOP equivalent:
$conn->set_charset("utf8");
有时您必须通过添加以下代码来定义主要的 php 字符集:
And sometimes you'll have to define the main php charset by adding this code:
mb_internal_encoding('UTF-8');
在客户端 HTML 端,您必须添加以下标题数据:
On the client HTML side you have to add the following header data :
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
为了使用 JSON AJAX 结果(例如通过使用 jQuery),您应该通过添加:
In order to use JSON AJAX results (e.g. by using jQuery), you should define the header by adding :
header("Content-type: application/json;charset=utf8");
json_encode(
some_data
);
这应该可以解决问题
相关文章