如何摆脱utf-8中无法识别的字符? mysql / php [英] how do i get rid of unrecognized characters in utf-8? mysql/php

查看:569
本文介绍了如何摆脱utf-8中无法识别的字符? mysql / php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个设置为utf-8的mysql数据库。
我已将我的php头设置为: header(Content-Type:text / html; charset = utf-8);
my html:< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>

I have a mysql database that's set to utf-8. I have set my php header to: header("Content-Type: text/html; charset=utf-8"); and in my html: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

当我返回任何包含圆括号或撇号的内容时,它们将显示为无法识别的字符(黑色菱形内部带有?)。

When I return anything that has round quotes or apostrophes, they show up as unrecognized characters (black diamond with a ? inside).

如果我对字符串运行utf8_encode()我回声,它看起来很好在Chrome,但在Firefox中显示不同的奇怪的字符。我可以在网站范围内进行其他操作吗?

If I run utf8_encode () on the string I'm echoing out, it looks fine in Chrome, but shows a different weird character in Firefox. Is there something else I can do site-wide to make this work better?

(我使用sequel pro和phpmyadmin访问了数据库)

(I've accessed the db with sequel pro and phpmyadmin)

推荐答案

完整utf-8设置:

1) .htaccess

AddDefaultCharset utf-8
PHP_VALUE default_charset utf-8

2)在 mysqli_connect()之后调用:

mysqli_query($this->link, 'SET character_set_client="utf8",character_set_connection="utf8",character_set_results="utf8"; ');

3)你的DB应该用collat​​ion:utf8charset;表中的所有字段也应为collat​​ion:utf8

3) your DB should be created with "collation: utf8" charset; all fields in table also should be "collation: utf8"

4)您的PHP文件也应使用utf8 charset创建

4) your PHP files also should be created with utf8 charset

这篇关于如何摆脱utf-8中无法识别的字符? mysql / php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆