Home > Article > Backend Development > What is the explode() function in PHP?
In this article, learn how to use the PHP Explode() function, which is a predefined built-in PHP function.
explode function is used to “split a string into” The explode function in PHP enables us to break a string into smaller contents by break. This delimiter is called a delimiter.
explode(delimiter, string, number of elements)
The explosion function accepts three parameters, two of which are mandatory and one is Optional.
Let us discuss these three parameters.
This character specifies the critical point or point where the string will be split i.e. whenever When this character is found in a string, it symbolizes the end of one element and the beginning of another element in the array.
The input string is to be split in the array.
This is an optional parameter. It is used to determine the number of array elements. This parameter can be any integer (positive, negative, or zero)
When this parameter is not provided, the returned array contains the total number of elements formed after the delimited string delimiter.
<?php $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 are not passing the third parameter, we are just creating a new array with the help of "space" delimiter, but in the In both expressions, we have instructed to create a new array containing only three elements by passing the third argument.
The above is the detailed content of What is the explode() function in PHP?. For more information, please follow other related articles on the PHP Chinese website!