HomeLanguagesPHP mb_split() Function

PHP mb_split() Function

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 neveropen"));
?>


Output:

Array
(
   [0] => Hello
   [1] => neveropen
)
 

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

RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32736 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7116 POSTS0 COMMENTS
Nicole Veronica
12250 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12333 POSTS0 COMMENTS
Shaida Kate Naidoo
7228 POSTS0 COMMENTS
Ted Musemwa
7488 POSTS0 COMMENTS
Thapelo Manthata
7208 POSTS0 COMMENTS
Umr Jansen
7180 POSTS0 COMMENTS