(PHP 4 >= 4.0.6, PHP 5, PHP 7)
mb_strcut — 获取字符的一部分
$str
, int $start
[, int $length = NULL
[, string $encoding = mb_internal_encoding()
]] )mb_strcut() 和 mb_substr() 类似,都是从字符串中提取子字符串,但是按字节数来执行,而不是字符个数。 如果截断位置位于多字节字符两个字节的中间,将于该字符的第一个字节开始执行。 这也是和 substr() 函数的不同之处,后者简单地将字符串在字节之间截断,这将导致一个畸形的字节序列。
str要截断的 string。
start
如果 start 不是负数,返回的字符串会从 str 的第 start 字节位置开始,从 0 开始计数。举个例子,字符串 'abcdef',字节位置 0 的字符是 'a',字节位置 2 的字符是
'c',以此类推。
如果 start 是负数,返回的字符串是从 str 末尾处第 start 个字节开始的。
length字节长度。If omitted or NULL is passed, extract all bytes to the end of the string.
encodingencoding
参数为字符编码。如果省略,则使用内部字符编码。
mb_strcut() 根据 start 和 length 参数返回 str 的一部分。
| 版本 | 说明 |
|---|---|
| 5.4.8 |
Passing NULL as length
extracts all bytes to the end of the string. Prior to this version
NULL was treated the same as 0.
|