PHP mb_split() Function
Last Updated :
27 Mar, 2023
The mb_split() is an inbuilt PHP function that split the multibyte strings with help of the regular expression.
Syntax:
mb_split(pattern,string,limit): array|false
Parameters: This function accepts 3 parameters:
- pattern: In this parameter, we define a regular expression that helps us to split a string.
- string: This parameter defines a string that’s going to be split using by pattern parameter.
- limit: This parameter is an optional parameter. This parameter defines the maximum limit of the split string.
Return value: If this function executes successfully then it will return an array otherwise it will return “false”.
Example 1: The following code demonstrates the mb_split() function.
PHP
<?php
print_r(mb_split( '\s' , "Hello GeeksforGeeks" ));
?>
|
Output:
Array
(
[0] => Hello
[1] => GeeksforGeeks
)
Example 2: The following code demonstrates the mb_split() function using a delimiter.
PHP
<?php
$string = "The,longest,sentence,in,English,is,also,awesome" ;
$characters = mb_split( "," , $string );
print_r( $characters );
?>
|
Output:
Array
(
[0] => The
[1] => longest
[2] => sentence
[3] => in
[4] => English
[5] => is
[6] => also
[7] => awesome
)
Reference: https://www.php.net/manual/en/function.mb-split.php
Share your thoughts in the comments
Please Login to comment...