Implode and Explode Function in PHP PDF
Implode and Explode Function in PHP PDF
In Focus
Blockc C# Corner
ASK A QUESTION CONTRIBUTE
1 5 590.5k
Implode() Function
The implode function is used to "join elements of an array with a string".
The implode() function returns a string from elements of an array. It takes an array of strings
and joins them together into one string using a delimiter (string to be used between the
pieces) of your choice.
The implode function in PHP is easily remembered as "array to string", which simply means
that it takes an array and returns a string. It rejoins any array elements and returns the
resulting string, which may be put in a variable.
Suppose you have an array like this $arr = Array ("A","E","I","O","U");
and you wish to combine it into a string, by putting the separator '-' between each element of
the array.
How to do that?
$str = implode("-",$arr);
So your resulting string variable $str will be contain:
A-E-I-O-U
Syntax
implode (separator , array)
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 1/9
3/11/2019 Implode() and Explode() Function in PHP
InExample
Focus 1
Blockc C# Corner
01. <html>
02. <body bgcolor="pink"> ASK A QUESTION CONTRIBUTE
03. <h3>Implode Function</h3>
04. <?php
05. $arr=array ('I','am','simple','boy!');
06. echo implode(" ",$arr);
07. ?>
08. </body>
09. </html>
Output
Example 2
01. <html>
02. <body bgcolor="pink">
03. <h3>Implode Function</h3>
04. <?php
05. $arr = array ('I','am','simple','boy!');
06. $space_separated = implode(" ", $arr);
07. $comma_separated = implode(" , ", $arr);
08. $slash_separated = implode(" / ", $arr);
09. $dot_separated = implode(" . ", $arr);
10. $hyphen_separated = implode(" - ", $arr);
11. echo $space_separated.'<br>';
12. echo $comma_separated.'<br>';
13. echo $slash_separated.'<br>';
14. echo $dot_separated.'<br>';
15. echo $hyphen_separated;
16. ?>
17. </body>
18. </html>
Output
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 2/9
3/11/2019 Implode() and Explode() Function in PHP
In Focus
Blockc C# Corner
Explode() Function
The explode function is used to "Split a string by a speci ed string into pieces i.e. it breaks a
string into an array".
The explode function in PHP allows us to break a string into smaller text with each break
occurring at the same symbol. This symbol is known as the delimiter. Using theexplode
command we will create an array from a string. The explode() function breaks a string into an
array, but the implode function returns a string from the elements of an array.
For example you have a string
$str="A E I O U";
now you want to make each name as an element of an array and access it individually so what
you do:
$arr = explode(",", $str);
means : we have made pieces of string $text based on separator ','
and put the resulting array in variable $arr
So I used print_r ($arr); and the results are the following:
Array(
[0] => A
[1] => E
[2] => I
[3] => O
[4] => U
)
which is equal to:
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 3/9
3/11/2019 Implode() and Explode() Function in PHP
In Focus
C# Corner
Blockc
$arr = Array ("A","E","I","O","U");
ASK A QUESTION CONTRIBUTE
Syntax
explode (separator,string,limit)
Example 1
01. <html>
02. <body bgcolor="pink">
03. <h3>Explode Function</h3>
04. <?php
05. $str="I am simple boy!";
06. print_r(explode(" ",$str));
07. ?>
08. </body>
09. </html>
Output
Example 2
01. <html>
02. <body bgcolor="pink">
03. <h3>Explode Function</h3>
04. <?php
05. $str="I am simple boy!";
06. print_r(explode("-",$str));
07. ?>
08. </body>
09. </html>
Output
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 4/9
3/11/2019 Implode() and Explode() Function in PHP
In Focus
Blockc C# Corner
Conclusion
So in this article you saw how to use the implode and explode functions in PHP. Using this
article one can easily understand the implode and explode functions in PHP.
Some Useful Resources
Functions in PHP
Include() and Require() Function in PHP
Mathematical Functions in PHP
Working with PHP functions with XAMPP
Date() Function in PHP
OUR BOOKS
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 5/9
3/11/2019 Implode() and Explode() Function in PHP
In Focus
Blockc C# Corner
Explode function in PHP Implode and Explode in PHP Implode function in PHP PHP tutorials
Vineet Kumar Saini is MCA quali ed with Honors from SunderDeep Engineering College
Ghaziabad. Currently he is working as a "WEB Developer" at AzylApps Technology Pvt. Ltd.
http://vineetsaini.wordpress.com/
177 4.8m 1
1 5
Type your comment here and press Enter Key (Minimum 10 characters)
good work..
Gowtham Rajamanickam Apr 28, 2016
57 22.8k 3.7m 1 0 Reply
nice article
dnn prasad May 21, 2012
1771 1 0 1 0 Reply
Thanks Vijay....
Vineet Kumar Saini Mar 17, 2012
177 10.9k 4.8m 1
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 6/9
3/11/2019 Implode() and Explode() Function in PHP
In Focus
Blockc C# Corner
लाखोंऐप िव ापनों
Google िवकेापनदाताओं
ज़ रए
तक तुरआयं त प बढ़ाएं
ं च ा कर
OUR TRAINING
TRENDING UP
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 7/9
3/11/2019 Implode() and Explode() Function in PHP
01 GraphQL In .NET Core Web API With Entity Framework Core - Part Three
In Focus
Blockc C# Corner
07 Create Registration And Login Page Using Angular 7 And Web API
08 GraphQL In .NET Core Web API With Entity Framework Core - Part One
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 8/9
3/11/2019 Implode() and Explode() Function in PHP
In Focus
About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ Partners
Blockc C# Corner C# Tutorials
©2019 C# Corner. All contents are ASK A QUESTION
copyright of their authors. CONTRIBUTE
https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/ 9/9