Open In App

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:

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
   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   
   $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

Article Tags :