PHP – mb_split (Multibyte Split) function

PHPServer Side ProgrammingProgramming

The mb_split() function in PHP is used to split a multibyte string using regular expressions. It returns the results in an array format.

Syntax

array mb_split($str_pattern, $str_string, int $limit=-1)

Parameters

mb_split() accepts the following three parameters −

  • $str_pattern − It is used for the regular expression's pattern.

  • $str_string − It is used to split the string.

  • $limit − It is an optional parameter that is used to specify the limit elements.

Return Values

The mb_split function will return the split elements result as an array. Or, it will return False on failure.

Example 1

<?php
   mb_internal_encoding("UTF-8");
   //mb_split function will split the string
   $string = mb_split(
      "[ ,]+", // Pattern
      "Welcome to the PHP Tutorial"); // string
   print_r($string);
?>

Output

It will produce the following output −

Array
(
   [0] => Welcome
   [1] => to
   [2] => the
   [3] => PHP
   [4] => Tutorial
)
raja
Updated on 11-Oct-2021 13:28:38

Advertisements