Home  >  Article  >  Backend Development  >  What is the explode() function in PHP?

What is the explode() function in PHP?

王林
王林forward
2023-09-04 13:01:061804browse

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.

Syntax

explode(delimiter, string, number of elements)

Parameters

The explosion function accepts three parameters, two of which are mandatory and one is Optional.

Let us discuss these three parameters.

Separator

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.

String

The input string is to be split in the array.

Number of elements

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)

Note

When this parameter is not provided, the returned array contains the total number of elements formed after the delimited string delimiter.

Example

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

Output:

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

Explanation

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete