What is explode() function in PHP?

In this article, figure out how to utilize PHP Explode() function which is a predefined inbuilt PHP function.

The explode function is utilized to "Split a string into pieces of elements to form an array".The explode function in PHP enables us to break a string into smaller content with a break. This break is known as the delimiter.


explode(separator, String, Number of Elements)


The explode function acknowledges three parameters of which two are compulsory and one is optional.

Let's discuss the three parameters.


This character specifies the critical points or points at which the string will split, i.e. whenever this character is found in the string it symbolizes the end of one element of the array and start of another.


The input string is to be split in the array.

Number of Elements

This is an optional parameter. It is utilized to determine the number of elements of the array. This parameter can be any integer(positive, negative or zero)


When this parameter is not provided the array returned contains the total number of the element formed after separating the string with the separator.


   $Original = "Hello,Welcome To Tutorials Point";
   print_r(explode(" ",$Original));
   print_r(explode(" ",$Original,3));


Array ( [0] => Hello,Welcome [1] => To [2] => Tutorials [3] => Point )
Array ( [0] => Hello,Welcome [1] => To [2] => Tutorials Point )


In the above example, in the first expression, we have not passed the third parameter and we are only creating the new array with the help of "space" delimiter but in the second expression, we have instructed to create the new array with only three elements by passing the third parameter.

Updated on: 29-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started