Hey everybody. I'm developing a new site (php5/mySQL) and am looking to finally get on the Unicode bandwagon. I'll admit to knowing next to absolutely nothing about supporting Unicode at the moment, but I'm hoping to resolve that with your help.
嘿,每一个人。我正在开发一个新站点(php5/mySQL),并希望最终赶上Unicode的潮流。我承认目前对支持Unicode几乎一无所知,但我希望在您的帮助下解决这个问题。
After desperately flexing my tiny, pathetic excuses for Googlefu-muscles, and scouring over each page that looked promising to my Unicode-newbie eyes, I have come to the conclusion that, while not entirely supported, my precious language of choice (PHP for those that have forgotten) has made at least a half-assed attempt at managing the foreign beast (and from what else I see, succeeding?). I have also come to the conclusion that
后拼命炫耀我的小可怜的借口Googlefu-muscles,和在每个页面看起来承诺我Unicode-newbie眼睛,我得出的结论,而不是完全支持,我的珍贵的语言选择的(那些已经忘记了PHP)使得至少一个不称职的尝试管理外国野兽(从我看到什么,成功吗?)。我也得出结论
<php header('Content-Type: text/html; charset=utf-8'); ?>
is a great place to start and that I should be looking into supporting UTF-8 since I have plenty of space on my (shared, for the moment) hosting.
这是一个很好的开始,我应该考虑支持UTF-8,因为我的主机上有足够的空间(目前是共享的)。
However, I'm not sure what this strange functionality known as mb_* means or how to incorporate it into functions such as strlen() and . . . to be honest at this point I don't know what other functionality (that I can't live without) is affected.
但是,我不确定这个称为mb_*的奇怪功能是什么意思,也不知道如何将它合并到诸如strlen()和…老实说,我不知道还有什么其他功能(我无法生存)会受到影响。
So I've come to you SO-ites in search of enlightenment and possibly straightening out my confused (where Unicode is concerned!) brain. I really want to support it but I need serious help.
所以我来找你们,是为了寻求启发,也许是为了理清我的困惑(关于Unicode的问题!)我真的很想支持它,但我需要认真的帮助。
P.S.: Does Unicode affect mysql_real_escape_string() or any other XSS prevention/security measures? I need to stay on top of this as well!
注:: Unicode是否影响mysql_real_escape_string()或任何其他XSS预防/安全措施?我也需要保持在这上面!
Thanks ahead of time.
提前谢谢。
- Adding Javascript into the mix, since I'll be using a mix of pure and jQuery and no knowing about Unicode support + this language. ;)
- 将Javascript添加到混合中,因为我将使用纯jQuery和纯jQuery的混合,不了解Unicode支持+这种语言。,)
3 个解决方案
#1
5
- Welcome onboard utf8 :)
- 欢迎机载utf8:)
- You should simply use mb_* functions in place of your traditional str* functions
- 您应该简单地使用mb_*函数来代替传统的str*函数
- MySQL and its API has long and well been supporting utf8, the only requirement that you use encoding when saving data and connecting. google for 'SET NAMES utf8'
- MySQL及其API长期以来一直支持utf8,这是在保存数据和连接时使用编码的惟一要求。“设置名称utf8”谷歌
- Note the 'u' modifier for preg_* functions that tells them to use unicode mode.
- 请注意preg_*函数的“u”修饰符,它告诉它们使用unicode模式。
#2
1
I hate to just give a list of links, but these are some that I found helpful:
我不想只给出一个链接列表,但我发现这些是有用的:
- http://developer.loftdigital.com/blog/php-utf-8-cheatsheet
- http://developer.loftdigital.com/blog/php-utf-8-cheatsheet
- http://www.herongyang.com/PHP/non_ascii_string.html
- http://www.herongyang.com/PHP/non_ascii_string.html
- http://www.herongyang.com/PHP/non_ascii_form.html
- http://www.herongyang.com/PHP/non_ascii_form.html
- http://www.phpwact.org/php/i18n/charsets
- http://www.phpwact.org/php/i18n/charsets
- http://www.phpwact.org/php/i18n/utf-8
- http://www.phpwact.org/php/i18n/utf-8
- http://kore-nordmann.de/blog/php_charset_encoding_FAQ.html
- http://kore-nordmann.de/blog/php_charset_encoding_FAQ.html
#3
0
When working with unicode:
当处理unicode:
- use
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
on top of your page when you output - 使用< meta内容= " text / html;输出时,charset=utf-8" http-equiv="Content-Type" />在页面顶部
- right after you connect to your database use the sql query:
mysql_query("set names 'utf8'");
- 在连接到数据库之后,使用sql查询:mysql_query(“设置名称‘utf8’”);
- make sure all tables and required fields have a collation type of: 'utf8_unicode_ci'
- 确保所有表和所需字段都具有以下排序类型:“utf8_unicode_ci”
#1
5
- Welcome onboard utf8 :)
- 欢迎机载utf8:)
- You should simply use mb_* functions in place of your traditional str* functions
- 您应该简单地使用mb_*函数来代替传统的str*函数
- MySQL and its API has long and well been supporting utf8, the only requirement that you use encoding when saving data and connecting. google for 'SET NAMES utf8'
- MySQL及其API长期以来一直支持utf8,这是在保存数据和连接时使用编码的惟一要求。“设置名称utf8”谷歌
- Note the 'u' modifier for preg_* functions that tells them to use unicode mode.
- 请注意preg_*函数的“u”修饰符,它告诉它们使用unicode模式。
#2
1
I hate to just give a list of links, but these are some that I found helpful:
我不想只给出一个链接列表,但我发现这些是有用的:
- http://developer.loftdigital.com/blog/php-utf-8-cheatsheet
- http://developer.loftdigital.com/blog/php-utf-8-cheatsheet
- http://www.herongyang.com/PHP/non_ascii_string.html
- http://www.herongyang.com/PHP/non_ascii_string.html
- http://www.herongyang.com/PHP/non_ascii_form.html
- http://www.herongyang.com/PHP/non_ascii_form.html
- http://www.phpwact.org/php/i18n/charsets
- http://www.phpwact.org/php/i18n/charsets
- http://www.phpwact.org/php/i18n/utf-8
- http://www.phpwact.org/php/i18n/utf-8
- http://kore-nordmann.de/blog/php_charset_encoding_FAQ.html
- http://kore-nordmann.de/blog/php_charset_encoding_FAQ.html
#3
0
When working with unicode:
当处理unicode:
- use
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
on top of your page when you output - 使用< meta内容= " text / html;输出时,charset=utf-8" http-equiv="Content-Type" />在页面顶部
- right after you connect to your database use the sql query:
mysql_query("set names 'utf8'");
- 在连接到数据库之后,使用sql查询:mysql_query(“设置名称‘utf8’”);
- make sure all tables and required fields have a collation type of: 'utf8_unicode_ci'
- 确保所有表和所需字段都具有以下排序类型:“utf8_unicode_ci”