PHP explode() Function

You are Here:

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)); ?>

Output

Array ( [0] => Learn [1] => PHP [2] => from [3] => Wikimass. )

Syntax

explode(separator, str, limit)

Parameter Values

ValueTypeExplanation
separatorRequiredSpecifies a character to break the string.
This parameter cannot be an empty string.
strRequiredSpecifies the string to split.
limitRequiredSpecifies 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
ArrayReturns 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)); ?>

Output

Array ( [0] => Learn [1] => PHP ) Array ( [0] => Learn PHP from Wikimass. ) Array ( [0] => Learn [1] => PHP from Wikimass. )

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.

We are working to cover every Single Concept in PHP.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author