This question already has answers here:
UTF-8 all the way through

(16个回答)


去年关闭。




您将推荐哪些扩展,以及如何最好地配置php以创建一个对所有内容都使用utf-8编码的网站。例如...
  • 页面输出为utf-8
  • 表单提交以utf-8编码的数据
  • 字符串数据的
  • 内部处理(例如,与数据库对话时)也都在utf-8中。

  • 看来php目前无法很好地应付多字节字符集。到目前为止,我已经知道mbstring看起来像是重要的扩展。

    这值得麻烦吗..?

    最佳答案

    带有Unicode内容的PHP的假定问题有些夸大了。自1998年以来,我一直在从事多语言网站的开发,但直到我在某个地方(很多年以后才开始阅读)之前,我才知道可能存在问题。

    这对我来说很好:

    Apache配置(在httpd.conf或.htaccess中)

    AddDefaultCharset utf-8
    

    PHP(在php.ini中)
    default_charset = "utf-8"
    mbstring.internal_encoding=utf-8
    mbstring.http_output=UTF-8
    mbstring.encoding_translation=On
    mbstring.func_overload=6
    

    的MySQL

    使用CREATE归类对数据库进行utf8_*编码,
    让表继承数据库排序规则,
    "SET NAMES utf8"开始每个连接

    HTML(在HEAD元素中)
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    

    关于php - 如何最好地配置PHP以处理UTF-8网站,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1605760/

    10-09 20:14
    查看更多