All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
构成Delphi工程的文件:窗体文件(.dfm)
SQL,Server处理数据层错误_[SQL,Server教程]
SQL存储过程入门级教程_[SQL Server教程]
XML,WebService完全实例详细解析_.net资料_编程技术
PHP+AJAX实现无刷新注册(带用户名实时检测)_[PHP教程]
visual c++中的组合框控件(Combo Box)
用AjaxPro实现无刷新翻页效果及数据库分页技术介绍_[AJAX教程]
如何让apache支持url_rewrite_php资料_编程技术
visual c++中常用MFC文件及库文件
解决PHP的Failed,opening,required问题_php资料_编程技术
Reading number is top 10 pictures
做运动的校花1
中国文革时期的色情图片2
修电脑也有这么漂亮的美女
Exquisite decoration is not paying too much4
Take you to walk into the most true north Korea rural3
胸部遭到偷窥的女人们
战场废物1
Original author said, this is the Hengyang people
鸡蛋的新玩法
传几朵花
Download software ranking
linux高级编程
电脑知识及技巧大合集
株洲本地在线棋牌游戏
徐若瑄成名作“魔鬼天使”
XML+Web+Service开发教程
jBuilder2006
网络管理员第三版
Boxer vs Yellow4
天龙八部十二宫服务端
Photoshop 8.0图象编辑软件
归海一刀 published in(发表于) 2014/2/17 7:35:41 Edit(编辑)
PHP技巧:PHP的mb_substr和mb_strcut的区别_[PHP教程]

PHP技巧:PHP的mb_substr和mb_strcut的区别_[PHP教程]

PHP技巧:PHP的mb_substr和mb_strcut的区别_[PHP教程]

php的mbstring扩展模块提供了多字节字符的处理能力,平常最常用的就是用mbstring来切分多字节的中文字符,这样可以避免出现半个字符的情况,由于是php的扩展,它的性能也要比一些自定义的多字节切分函数要好上一些。


mbstring extension提供了几个功能类似的函数,mb_substr和mb_strcut,看看手册上对它们的解释。


mb_substr
mb_substr() returns the portion of str specified by the start and length parameters.


mb_substr() performs multi-byte safe substr() operation based on number of characters. Position is counted from the beginning of str. First character's position is 0. Second character position is 1, and so on.


mb_strcut
mb_strcut() returns the portion of str specified by the start and length parameters.


mb_strcut() performs equivalent operation as mb_substr() with different method. If start position is multi-byte character's second byte or larger, it starts from first byte of multi-byte character.


It subtracts string from str that is shorter than length AND character that is not part of multi-byte string or not being middle of shift sequence.


举个例子来说,有一段文字, 分别用mb_substr和mb_strcut来做切分:


PLAIN TEXT
CODE:
str = '我是一串比较长的中文-www.dwww.cn';

echo "mb_substr:" . mb_substr(str, 0, 6, 'utf-8');

echo "
";

echo "mb_strcut:" . mb_strcut(str, 0, 6, 'utf-8');
?>
输出结果如下:


mb_substr:我是一串比较
mb_strcut:我是







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.