Current Location: Home> Function Categories> mb_str_split

mb_str_split

Given a multibyte string, return its character array
Name:mb_str_split
Category:Multi-byte string
Programming Language:php
One-line Description:Split the string into a single character and return an array containing the split characters

Function name: mb_str_split()

Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8

Usage: mb_str_split(string $string, int $length = 1, string $encoding = null): array|false

Description: The mb_str_split() function splits a string into a single character and returns an array containing the split characters. This function is multibyte-safe and can handle various character encodings.

parameter:

  • $string: The string to be split.
  • $length: The length of each split character. The default is 1, which means splitting the string into a single character.
  • $encoding: Optional parameter, specifying the character encoding of the string. If not provided, internal character encoding is used.

Return value:

  • When successful, return an array containing the split characters.
  • If the parameter is invalid or an error occurs, false is returned.

Example:

 $str = "Hello PHP"; $result = mb_str_split($str); print_r($result);

Output:

 Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => P [7] => H [8] => P )

In the above example, we use the mb_str_split() function to split the string "Hello PHP" into a single character and store the result in the array $result. Finally, use the print_r() function to print the output result.

Similar Functions
Popular Articles