Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

php - Strategy for supporting unicode & multi language in PHP5

I have heard that PHP6 will natively support unicode, which will hopefully make multi-language support much easier. However, PHP5 has pretty weak support for unicode and multi-language (i.e. just a bunch of specialized string functions).

I was wondering what are your strategies to enable unicode and multi-languaage support in your PHP5 applications?

Also, how do you store translations since PHP5 doesn't have WebResource file like ASP.NET does?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's not all that hard really, but you may want to make your question a bit more specific.

If you're talking to a database, make sure your database stores data in UTF-8 and the connection to your database is in UTF-8 (a common pitfall). Make sure to run this when establishing a connection:

mysql_set_charset('utf8');

For user input, set the accept-charset attribute on your forms.

<form accept-charset="utf-8">

Serve your sites with an appropriate HTTP header:

header('Content-Type: text/html; charset=utf-8');

or at least set appropriate meta tags for your site:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Keep your source code files encoded in UTF-8.

If you keep everything in UTF-8, you usually don't need to worry about anything. It's only getting problematic once you start mixing encodings throughout your app.

If you're starting to talk about string manipulation of course, you'll have to take a little more care. Mostly you'll want to use the mb_ set of string functions, as you pointed out yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...