How can character encoding be made correctly in both php and mysql database
布尔奇1(P)Searching high&;low for a solution.I've tried many variations before then the question.(p)(P)What is required to have names appear the same in PPMyadmin and html page?这还可以吗?(p)(P)Edit 1:It would seem that this is a myscal issue.Why?Because the PHP generated HTML page will always show the correct characters.就在这一点上,这只是一个不正确的表现的数据库。(p)(P)Edit 2:Clarification.随着原始的定居点在代码SNIP和图像的范围内拍摄,(p)
(P)Adding the EDOCX1 English 0(p)
(P)结束编辑2(p)(P)In a Mysql Database,Viewed with PPMyadmin:字母名称(p)(P)The items appear in the database like this:(I've modified the first jo?(o)上诉改正数据库(p)(P)字母名称(p)(P)and in the html page with encourage set the names appear like(order is reversed&;modified has black diamond),(p)(P)MGXY1音标2(p)(P)字母名称:字母名称(p)(P)I have tried changing the column collation to UTF8°U bin,UTF8°UU CI,UTF8°UU Unide°CI,all with no change to either side.Also changed the document(bbedit)from UTF-8 to UTF-8(with BOM),ISO Latin 1 and Windows Latin 1.Several of these created more black diamonds,making the issue worse.(Set to UTF-8 in images)I even tried to preg□ureplace?,等与缩小相等。(p)(P)短期故事是,乔?O is entered on the page(content type above),Jo?65505O is in database,and JO?或者你来了HTML page on reshesh.(p)(P)寻找思想。Thanks.(p)
字符集问题通常很难解决。基本上,您需要确保以下所有内容都是正确的:
- 数据库连接使用的是UTF-8
- DB表使用的是UTF-8
- DB表中的各个列使用的是UTF-8
- 数据实际上是以utf-8编码正确存储在数据库中的(如果您从错误的源导入数据,或者更改了表或列的排序规则,则通常不是这样)
- 网页正在请求UTF-8
- 阿帕奇提供UTF-8
这里有一个关于处理这个列表的很好的教程,从开始到结束:http://www.bluebox.net/news/2009/07/mysql_encoding/
听起来好像你的问题是你有双重编码(或三重编码)的字符,可能是因为你改变了字符集或者导入了已经编码的数据,但字符集不正确。在上面的教程中有一个完整的部分介绍如何修复它。
确保您的数据库连接也使用UTF-8。试着把下面的一行放在页面的顶部,
1 |
确保您的HTML页面以及参与Ajax数据交换的脚本都具有适当的HTTP头,包括
1 | Content-Type: text/html; charset=UTF-8 |
因为HTML端编码设置可能被浏览器忽略
默认php不使用utf8。确保您使用的是mbstring函数,而不是通常的内置字符串函数。