php + mysql + html + javascript = i18n头痛 [英] php + mysql + html + javascript = i18n headache

查看:96
本文介绍了php + mysql + html + javascript = i18n头痛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对我来说一直是个问题,性格问题。我一直试图用小补丁来解决我的问题,实际上这永远不能解决我现实中的问题。所以我正在寻找非常强大的解决方案来解决所有这些问题。我想了解大型应用程序(Facebook,Google,其他多语言ajax应用程序和apis)解决了这个问题。我想要一个解决方案,它将解决我所有的字符编码等问题。我使用php,mysql,html和javascript来创建我的应用程序,所以解决方案应该一起解决所有问题或所有这些语言。如果您编写完整配置,这是完美的,但如果有很长的文档,我可以阅读它。我需要帮助 。谢谢 。 我无法通过所有这些语言正确传输字符串(文本)


  1. 我也从外部apis获取数据。我应该如何照顾他们
  2. 解析方案

如果你坚持使用Unicode
$ b


  • 将MySQL表编码设置为UTF-8

  • 确保您的通过运行 SET NAMES utf8

  • 以UTF-8与数据库进行交谈将所有源代码保存为UTF- 8

  • 在PHP中处理可能包含UTF-8字符的字符串时,请使用 mb _ 函数
  • 发送HTTP内容类型标头,表示内容为UTF -8
  • Javascript本质上是UTF-8,所以你应该不用担心它。



问题是不同的技术默认为d不同的字符编码。不幸的是,字符串没有附加隐式编码元数据,它们只是字节序列。除非被告知,否则字符串的接收者只能猜测该序列的编码应该是什么。每次连接两件任何东西时,都需要确保它们使用的是相同的编码(或者您需要专门从一种编码转换为另一种编码)。总是假设你必须在某个地方定义编码,需要怎么做取决于技术。


This has been always a problem for me , Character problem . I always tried to solve my problem with little patches , actually this never solves my problem in reality.So I am looking for very strong solution to solve all these problems.I want to learn how big apps(facebook , google, other multi lingual ajax apps and apis) solve this problem. I want a solution which will solve all my character encoding , etc problems.I use php, mysql, html and javascript to create my application , so the solution should solve all problems or all these languages together.If you write full configuration this is perfect , but if there is a long long document , I can read it to . I need help . Thank you . I can not transfer string(text) correctly through all these languages

  1. Also I pull data from external apis.How should I take care of them

解决方案

It's pretty easy if you just stick to using Unicode everywhere.

  • set MySQL table encodings to UTF-8
  • make sure you're talking to the database in UTF-8 by running SET NAMES utf8
  • save all your source code in UTF-8
  • when manipulating strings in PHP which may contain UTF-8 characters, use the mb_ functions
  • send HTTP Content-Type headers denoting that the content is in UTF-8
  • Javascript is intrinsically UTF-8, so you should have no worries there

The thing is that different technologies default to different character encodings. Unfortunately strings do not have implicit encoding metadata attached, they're just sequences of bytes. Unless being told, the receiver of a string can only make a best guess what encoding that sequence is supposed to be in. Whenever connecting two pieces of anything, you need to make sure they're using the same encoding (or you need to specifically convert from one encoding to the other). Always assume that you have to define the encoding somewhere, how exactly that needs to be done depends on the technology.

这篇关于php + mysql + html + javascript = i18n头痛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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