PHP explode() Function

Last Updated:

PHP explode()

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

Note: This function is binary-safe.

Example

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

Syntax

explode(separator, str, limit)

Parameter Values

ValueTypeExplanation
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

ValueExplanation
Array Returns an array of strings.

More Examples

Example

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