In PHP, the explode()
function is used to split a string into a series of tokens (substrings extracted from the original string) based on a particular delimiter. In other words, the explode()
function converts a string into an array.
explode(separator, string, limit)
separator
: Specifies the token where the string needs to split.
string
: The string that needs to split.
limit
: An optional parameter that specifies the number of array elements that should be returned.
The following code runs the explode()
function without the limit parameter.
<?php$str = "Hello world. This is educative";print_r (explode(" ", $str));?>
The following code runs the explode()
function with the limit parameter.
<?php$str = "Hello,world,This,is,educative";print_r(explode(',',$str,2));?>
Free Resources