mb_strcut

(PHP 4 >= 4.0.6, PHP 5, PHP 7)

mb_strcut获取字符的一部分

说明

mb_strcut ( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_encoding() ]] ) : string

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.

encoding

encoding 参数为字符编码。如果省略,则使用内部字符编码。

返回值

mb_strcut() 根据 startlength 参数返回 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.

参见

相关文章
php 多字节字符串 函数 转换字符的编码php 多字节字符串 函数 convert kana one from another zen kaku han kaku and more php 多字节字符串 函数 转换一个或多个变量的字符编码php 多字节字符串 函数 根据 html 数字字符串解码成字符php 多字节字符串 函数 检测字符的编码php 多字节字符串 函数 设置/获取 字符编码的检测顺序php 多字节字符串 函数 returns position and length of a matched part of the multibyte regular expression for a predefined multibyte stringphp 多字节字符串 函数 returns the matched part of a multibyte regular expressionphp 多字节字符串 函数 检测 http 输入字符编码php 多字节字符串 函数 设置/获取 http 输出字符编码php 多字节字符串 函数 设置/获取内部字符编码php 多字节字符串 函数 在输出缓冲中转换字符编码的回调函数php 多字节字符串 函数 获取 mime 字符串php 多字节字符串 函数 set/get character encoding for multibyte regexphp 多字节字符串 函数 获取字符的一部分php 多字节字符串 函数 查找指定字符在另一个字符串中最后一次的出现php 多字节字符串 函数 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现php 多字节字符串 函数 查找字符串在另一个字符串里的首次出现php 多字节字符串 函数 设置/获取替代字符php 字符串 函数 转换字符串第一个字节为 0 255 之间的值
关注编程学问公众号