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 )
注意事項: