PHP下,截取中文字符串

来源:互联网 发布:seajs require其他js 编辑:程序博客网 时间:2024/04/30 03:08



One Chinese char inUFT-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 goodecho mb_substr($match->homegroup, 0, 3); // works, will output '丙' , but not goodecho 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

原创粉丝点击