php + mysql + html + javascript = i18n头痛 [英] php + mysql + html + javascript = i18n headache
问题描述
- 我也从外部apis获取数据。我应该如何照顾他们 解析方案
如果你坚持使用Unicode
$ b
SET NAMES utf8
mb _
函数
问题是不同的技术默认为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
- 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屋!