PHP explode() Function

Last Updated:

PHP explode()

The explode() function splits a string by the given separator.

Note: This function is binary-safe.


PHP Compiler
<?php $str = "Learn PHP from Wikimass."; // space separator. print_r (explode(" ", $str)); ?>


explode(separator, str, limit)

Parameter Values

separator Required Specifies a character to break the string.
This parameter cannot be an empty string.
str Required Specifies the string to split.
limit Required Specifies the maximum number of elements in the output array.
Possible Values:
  • -ve - Returns an array except for the last -limit element(s).
  • 0 - Returns an array with one element.
  • +ve - Returns an array with a maximum of limit element(s).

Return Value

Array Returns an array of strings.

More Examples


PHP Compiler
<?php $str = "Learn PHP from Wikimass."; print_r (explode(" ", $str, -2)); echo "<br>"; print_r (explode(" ", $str, 0)); echo "<br>"; print_r (explode(" ", $str, 2)); ?>

Share this Page

Meet the Author