您的位置:首页 > 编程语言 > PHP开发

PHP下,截取中文字符串

2011-11-23 11:17 197 查看
One Chinese char in
UFT-8 encoding holds 3 bytes
, and let's suppose that your string is encoded by 'UTF-8', and you've already set your page's encoding method is 'UTF-8',
then the following lines will make it:

$match->homegroup = '丙組';
echo substr($match->homegroup, 0, 3); // works, will output '丙' , but not good

echo mb_substr($match->homegroup, 0, 3); // works, will output '丙' , but not good

echo mb_substr($match->homegroup, 0, 1, "UTF-8"); // works, will output '丙'


Just stop here, since it get the work done. And will be back soon!

REFs:

http://blog.xuite.net/chenbruse/bruse/13351768

http://blog.linym.net/archives/74

http://zoearthmoon.blogspot.com/2010/03/phpsubstr.html

http://www.wretch.cc/blog/herbjoyce/9665218
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: