mb_split
使用正则表达式分割多字节字符串
函数名:mb_split()
适用版本:PHP 4 >= 4.2.0, PHP 5, PHP 7
函数说明:mb_split() 函数使用多字节字符集进行字符串分割,并返回一个由分割后的子字符串组成的数组。
语法:mb_split(string $pattern, string $string [, int $limit = -1])
参数:
返回值:返回一个由分割后的子字符串组成的数组,如果分割失败则返回 FALSE。
示例:
// 使用空格分割字符串
$str = "Hello World";
$result = mb_split(" ", $str);
print_r($result);
// Output: Array ( [0] => Hello [1] => World )
// 使用正则表达式分割字符串
$str = "Hello,World";
$result = mb_split("[,]", $str);
print_r($result);
// Output: Array ( [0] => Hello [1] => World )
// 限制返回的数组元素个数
$str = "Hello World";
$result = mb_split(" ", $str, 1);
print_r($result);
// Output: Array ( [0] => Hello )
注意事项: