PHP 和mysql 将非编码转换为unicode
我在我们的网站上有这样的字符: Fémnyomà
这是一个街道地址,用另一种语言输入(尽管我不知道是哪种语言)。这是数据库设置:
mysql 4.1.2log
charset cp1252 West European (latin1)
我使用 PHP,但没有 mbstrings() (尽管我对此地址没有进行字符串转换,只是回显)。
如果我将 mysql 字符集从 cp1252 更改为 UTF-8 并确保使用 header( 'Content-Type: text/html; charset=UTF-8' );
这样的东西会改善我的情况?或者,数据是否因为保存在 cp1252 字符集中而被存储,而我无能为力?原始数据库创建于 2002 年,此后一直在使用/扩展。我们已经升级了服务器并重新导入了转储,但遗憾的是我承认没有过多考虑字符集。
如果我被淹没了,我可能只会删除这些字段中的文本,但我想继续支持 unicode,所以如果我发出 ALTER database_name DEFAULT CHARACTER SET utf8; 会确保未来的多字节编码是否正确保存,至少将存储排除在外(让我担心 PHP)?
谢谢 -
I have characters like these on our web site: Fémnyomó
That is a street address, entered in another language (though I do not know which). Here's the db setup:
mysql 4.1.2log
charset cp1252 West European (latin1)
I'm using PHP but without mbstrings() (though I do no string conversions on this address, just echo).
If I changed the mysql charset from cp1252 to UTF-8 and made sure I used things like header( 'Content-Type: text/html; charset=UTF-8' );
would that improve my situation? Or, is the data hosed because it was saved in the cp1252 charset and there is nothing I can do? The original database was created in 2002 and has been used/expanded since. We've upgraded servers and re-imported dumps but ashamedly I admit to not giving charsets much thought.
If I'm hosed, I'll probably just remove the text in those fields but I'd like to support unicode going forward, so if I issue ALTER database_name DEFAULT CHARACTER SET utf8;
will that make sure future multibyte encodings are saved correctly, taking at least storage out of the equation (leaving me to worry about PHP)?
Thanks -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 将所有字符集转换为 UTF8:
2) 在页面上的任何查询之前发出此命令:
3) 使用此标头:
4) 插入此元标记:
5) 另外,请阅读以下内容: oreillynet.com/onlamp/blog/2006/01/turning_mysql_data_in_latin1_t.html" rel="nofollow noreferrer">http://www.oreillynet.com/onlamp/blog/2006/01/turning_mysql_data_in_latin1_t.html
1) Convert all charsets to UTF8:
2) Issue this before any query on the page:
3) Use this header:
4) Insert this meta tag:
5) Also, read this: http://www.oreillynet.com/onlamp/blog/2006/01/turning_mysql_data_in_latin1_t.html