![]() |
VOOZH | about |
The preg_split() function is an inbuilt function in PHP which is used to convert the given string into an array. The function splits the string into smaller strings or sub-strings of length which is specified by the user. If the limit is specified then small string or sub-strings up to limit return through an array. The preg_split() function is similar to explode() function but the difference is used to the regular expression to specify the delimiter but explode is not used it.
Syntax:
array preg_split( $pattern, $subject, $limit, $flag )
Parameter: This function accepts four parameters as mentioned above and described below:
Return Value: This function returns an array after the split boundaries matched. When the limit of the original array or string exceeds then returns with an array element otherwise it's False. Below programs illustrate the preg_split() function in PHP:
Program 1:
Array ( [0] => G [1] => e [2] => e [3] => k [4] => s [5] => a [6] => r [7] => t [8] => i [9] => c [10] => l [11] => e )
Program 2:
Array ( [0] => Geeks [1] => for [2] => Geeks )
Program 3:
Array ( [0] => Array ( [0] => ne [1] => 11 ) [1] => Array ( [0] => arc [1] => 15 ) [2] => Array ( [0] => ive [1] => 19 ) [3] => Array ( [0] => 2018 [1] => 23 ) )
Reference: https://www.php.net/manual/en/function.preg-split.php