PHP explode Function

What is explode Function in string?

Explanation

The "explode" function always used to break or split a string into an array in PHP.

Syntax:


explode(separator,string,limit)

In the above syntax, "seperator" specifies where to break the strings, "string" specifies the strings to be split,"limit" specifies the number of array elements to be returned.

Example :


<?php
$str = "Hey how are you!";
print_r(explode(" ",$str));
?>
Result :

Array
(
[0] => Hey
[1] => how
[2] => are
[3] => you!
)

In the above PHP example the string "$str" is split into 4 array elements based on the blankspace between words.

PHP Topics


Ask Questions

Ask Question