PHP explode() Function
You are Here:
PHP explode()
The explode()
function splits a string by the given separator.
Note: This function is binary-safe.
Example
PHP Compiler
<?php
$str = "Learn PHP from Wikimass.";
// space separator.
print_r (explode(" ", $str));
?>
Output
Array ( [0] => Learn [1] => PHP [2] => from [3] => Wikimass. )
Syntax
explode(separator, str, limit)
Parameter Values
Value | Type | Explanation |
---|---|---|
separator | Required | Specifies a character to break the string. This parameter cannot be an empty string. |
str | Required | Specifies the string to split. |
limit | Required | Specifies the maximum number of elements in the output array. Possible Values:
|
Return Value
Value | Explanation |
---|---|
Array | Returns an array of strings. |
More Examples
Example
PHP Compiler
<?php
$str = "Learn PHP from Wikimass.";
print_r (explode(" ", $str, -2));
echo "<br>";
print_r (explode(" ", $str, 0));
echo "<br>";
print_r (explode(" ", $str, 2));
?>
Output
Array ( [0] => Learn [1] => PHP )
Array ( [0] => Learn PHP from Wikimass. )
Array ( [0] => Learn [1] => PHP from Wikimass. )
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on PHP with examples for quick and easy learning.
We are working to cover every Single Concept in PHP.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.