The explode() function is an built-in function in PHP which is used to break or split a string into an array by a separator string like comma, hyphen, space etc. This function is binary-safe.
separator – This parameter is required. It specifies where to break the string.
string – This parameter is required. The string to split.
limit – This parameter is Optional. It specify the number of array elements to return.
The Explode() function returns:
- Greater than 0 – An array with a maximum of limit elements.
- Less than 0 – An array except for the last -limit elements.
- 0 – An array with one element.
<?php $str = 'A good programmer looks both ways before crossing a one-way street.'; print_r(explode(" ",$str)); echo "<br>"; print_r(explode(" ",$str,5)); ?>
Array (  => A  => good  => programmer  => looks  => both  => ways  => before  => crossing  => a  => one-way  => street. ) Array (  => A  => good  => programmer  => looks  => both ways before crossing a one-way street. )