mb_substr

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

mb_substr获取部分字符串

说明

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

根据字符数执行一个多字节安全的 substr() 操作。 位置是从 str 的开始位置进行计数。 第一个字符的位置是 0。第二个字符的位置是 1,以此类推。

参数

str

从该 string 中提取子字符串。

start

如果 start 不是负数,返回的字符串会从 strstart 的位置开始,从 0 开始计数。举个例子,字符串 'abcdef',位置 0 的字符是 'a',位置 2 的字符是 'c',以此类推。

如果 start 是负数,返回的字符串是从 str 末尾处第 start 个字符开始的。

length

str 中要使用的最大字符数。如果省略了此参数或者传入了 NULL,则会提取到字符串的尾部。

encoding

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

返回值

mb_substr() 函数根据 startlength 参数返回 str 中指定的部分。

更新日志

版本 说明
5.4.8 length 传入 NULL,则从 start 提取到字符串的结尾处。 在之前的版本里, NULL 会被当作 0 来处理。

参见

相关文章
php 多字节字符串 函数 检查字符串在指定的编码里是否有效php 多字节字符串 函数 get a specific characterphp 多字节字符串 函数 对字符串进行大小写转换php 多字节字符串 函数 转换字符的编码php 多字节字符串 函数 convert kana one from another zen kaku han kaku and more php 多字节字符串 函数 returns start point for next regular expression matchphp 多字节字符串 函数 retrieve the result from the last multibyte regular expression matchphp 多字节字符串 函数 setup string and regular expression for a multibyte regular expression matchphp 多字节字符串 函数 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 多字节字符串 函数 get code point of characterphp 多字节字符串 函数 在输出缓冲中转换字符编码的回调函数php 多字节字符串 函数 解析 get/post/cookie 数据并设置全局变量php 多字节字符串 函数 获取 mime 字符串php 多字节字符串 函数 大小写不敏感地查找指定字符在另一个字符串中最后一次的出现php 多字节字符串 函数 大小写不敏感地在字符串中查找一个字符串最后出现的位置php 多字节字符串 函数 查找字符串在一个字符串中最后出现的位置php 多字节字符串 函数 查找字符串在另一个字符串里的首次出现php 多字节字符串 函数 获取部分字符串php 字符串 函数 转换字符串第一个字节为 0 255 之间的值
关注编程学问公众号