简体   繁体   中英

php + mysql + html + javascript = i18n headache

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM