Current Location: Home> Function Categories> mb_split

mb_split

Splitting multibyte strings using regular expressions
Name:mb_split
Category:Multi-byte string
Programming Language:php
One-line Description:Use a multibyte character set for string segmentation and return an array of segmented substrings

Function name: mb_split()

Applicable version: PHP 4 >= 4.2.0, PHP 5, PHP 7

Function description: The mb_split() function uses a multibyte character set to split strings and returns an array composed of segmented substrings.

Syntax: mb_split(string $pattern, string $string [, int $limit = -1])

parameter:

  • $pattern: The specified delimiter, which can be a string or regular expression.
  • $string: The string to be split.
  • $limit (optional): Specifies the maximum number of elements to return the array. The default value is -1, indicating that the number of returned array elements is not limited.

Return value: Returns an array composed of divided substrings, and returns FALSE if splitting fails.

Example:

 // 使用空格分割字符串$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 )

Notes:

  • The mb_split() function uses a multibyte character set for segmentation, and it is necessary to ensure that the mbstring extension is enabled in the PHP environment.
  • If the split fails, the mb_split() function returns FALSE.
  • If the $limit parameter is not specified, all split substrings will be returned.
Similar Functions
Popular Articles