Definition
The explode() function breaks a string into an array.
Syntax
explode(separator, string, limit)
Parameters
Parameter | Description |
---|---|
separator |
Required. Specifies where to break the string. |
string |
Required. The string to split. |
limit |
Optional. Specifies the number of array elements to return. Possible values:Greater than 0 - Returns an array with a maximum of limit element(s)Less than 0 - Returns an array except for the last -limit elements()0 - Returns an array with one element |
Example
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ", $str));
echo "<br>";
print_r(explode(',', $str, 0));
echo "<br>";
// positive limit
print_r(explode(',', $str, 2));
echo "<br>";
// negative limit
print_r(explode(',', $str, -1));
echo "<br>";