PHP explode() function splits or breaks an array into strings. It splits an array based on the delimiter. You have to specify the character delimiter (like comma(,)) in a string from where the string will split.
Syntax
explode(separator, string, limit)
Parameter Description
Name | Description |
---|---|
separator | Required. Specify the character present in a string where to split or break an array |
string | Required. The string is to be broken into an array. |
limit | optional. The no of array elements to return.
|
Let’s find out the use of the PHP explode()
Function with the examples given below.
Examples of PHP explode() Function
Example 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $mystr = 'HTML, CSS, PHP, jQuery, javascript'; //Without limit print_r(explode(",", $mystr)); echo "<br>"; //With positive(+ve) limit print_r(explode(",", $mystr, 2)); echo "<br>"; //With negative(-ve) limit print_r(explode(",", $mystr, -1)); echo "<br>"; //With zero(0) limit print_r(explode(",", $mystr)); echo "<br>"; ?> |