- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
<?php $Original = "Hello,Welcome To Tutorials Point"; print_r(explode(" ",$Original)); print_r(explode(" ",$Original,3)); ?>
Array (  => Hello,Welcome  => To  => Tutorials  => Point ) Array (  => Hello,Welcome  => To  => 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.
- explode() function in PHP
- What is header() function in PHP?
- What is implode() function in PHP?
- How can I remove all empty values when I explode a string using PHP?
- What is traits in PHP?
- What is .htaccess in PHP?
- What is method overloading in PHP?
- What is dependency injection in PHP?
- What is Exception Handling in PHP ?
- What is Trailing Comma in PHP?
- What is PHP Output Buffering?
- file_exists() function in PHP
- basename( ) function in PHP
- chgrp()function in PHP