标题: PHP网站制作之PHP的mb_substr和mb_strcut的区分 [打印本页] 作者: 活着的死人 时间: 2015-2-16 00:25 标题: PHP网站制作之PHP的mb_substr和mb_strcut的区分 熟悉了PHP和MYSQL开发的要领之后,再回头看你写的那个留言本,你也许会怀疑那真的是你写的吗?当然,如果屋里还有鬼的话,也许是它写的-_- 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:
<?php
$str = '我是一串对照长的中文-www.webjx.com';