SlideShare a Scribd company logo
PHP Tutorials By Vineet Kumar Saini

             Implode() and Explode() Function in PHP

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)

Example1

<html>
<body bgcolor="pink">
<h3>Implode Function</h3>
<?php
$arr=array ('I','am','simple','boy!');
echo implode(" ",$arr);
?>
</body>
</html>

Output
PHP Tutorials By Vineet Kumar Saini




Example2

<html>
<body bgcolor="pink">
<h3>Implode Function</h3>
<?php
$arr = array ('I','am','simple','boy!');
$space_separated = implode(" ", $arr);
$comma_separated = implode(" , ", $arr);
$slash_separated = implode(" / ", $arr);
$dot_separated = implode(" . ", $arr);
$hyphen_separated = implode(" - ", $arr);
echo $space_separated.'<br>';
echo $comma_separated.'<br>';
echo $slash_separated.'<br>';
echo $dot_separated.'<br>';
echo $hyphen_separated;
?>
</body>
</html>

Output
PHP Tutorials By Vineet Kumar Saini




Explode() Function

The explode function is used to "Split a string by a specified 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 the explode
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:

$arr = Array ("A","E","I","O","U");
PHP Tutorials By Vineet Kumar Saini


Syntax

explode (separator,string,limit)

Example1

<html>
<body bgcolor="pink">
<h3>Explode Function</h3>
<?php
$str="I am simple boy!";
print_r(explode(" ",$str));
?>
</body>
</html>

Output




Example2

<html>
<body bgcolor="pink">
<h3>Explode Function</h3>
<?php
$str="I am simple boy!";
print_r(explode("-",$str));
?>
</body>
</html>
PHP Tutorials By Vineet Kumar Saini

Output




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.

More Related Content

PPTX
Trabajo practico de telecomunicaciones
Juan Ignacio Carestía
 
PDF
Dropdown List in PHP
Vineet Kumar Saini
 
PDF
Pagination in PHP
Vineet Kumar Saini
 
PDF
Country State City Dropdown in PHP
Vineet Kumar Saini
 
PPTX
Unit 2-Arrays.pptx
mythili213835
 
PPTX
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
PPTX
UNIT II (7).pptx
DrDhivyaaCRAssistant
 
PPTX
UNIT II (7).pptx
DrDhivyaaCRAssistant
 
Trabajo practico de telecomunicaciones
Juan Ignacio Carestía
 
Dropdown List in PHP
Vineet Kumar Saini
 
Pagination in PHP
Vineet Kumar Saini
 
Country State City Dropdown in PHP
Vineet Kumar Saini
 
Unit 2-Arrays.pptx
mythili213835
 
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 
UNIT II (7).pptx
DrDhivyaaCRAssistant
 
UNIT II (7).pptx
DrDhivyaaCRAssistant
 

Similar to Implode & Explode in PHP (20)

PPT
Php, mysqlpart2
Subhasis Nayak
 
PPTX
Chapter 2 wbp.pptx
40NehaPagariya
 
PPTX
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Dhivyaa C.R
 
PPTX
UNIT IV (4).pptx
DrDhivyaaCRAssistant
 
ODP
PHP Web Programming
Muthuselvam RS
 
PPTX
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
PPTX
Tokens in php (php: Hypertext Preprocessor).pptx
BINJAD1
 
PPTX
3160713_WP_GTU_Study_Material_Presentations_Unit-5_17042022102823PM.pptx
jignasha15
 
PDF
Array String - Web Programming
Amirul Azhar
 
PPTX
Different uses of String in Python.pptx
AryadipDey
 
PPTX
Diploma ii cfpc u-4 function, storage class and array and strings
Rai University
 
PPTX
Btech i pic u-4 function, storage class and array and strings
Rai University
 
PDF
Functions torage class and array and strings-
aneebkmct
 
PPTX
Mcai pic u 4 function, storage class and array and strings
Rai University
 
PPTX
function, storage class and array and strings
Rai University
 
PPT
Class 5 - PHP Strings
Ahmed Swilam
 
PPT
Java Script Introduction
jason hu 金良胡
 
PPTX
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
PPTX
Array-single dimensional array concept .pptx
SindhuVelmukull
 
Php, mysqlpart2
Subhasis Nayak
 
Chapter 2 wbp.pptx
40NehaPagariya
 
Regular expressions, Session and Cookies by Dr.C.R.Dhivyaa Kongu Engineering ...
Dhivyaa C.R
 
UNIT IV (4).pptx
DrDhivyaaCRAssistant
 
PHP Web Programming
Muthuselvam RS
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Tokens in php (php: Hypertext Preprocessor).pptx
BINJAD1
 
3160713_WP_GTU_Study_Material_Presentations_Unit-5_17042022102823PM.pptx
jignasha15
 
Array String - Web Programming
Amirul Azhar
 
Different uses of String in Python.pptx
AryadipDey
 
Diploma ii cfpc u-4 function, storage class and array and strings
Rai University
 
Btech i pic u-4 function, storage class and array and strings
Rai University
 
Functions torage class and array and strings-
aneebkmct
 
Mcai pic u 4 function, storage class and array and strings
Rai University
 
function, storage class and array and strings
Rai University
 
Class 5 - PHP Strings
Ahmed Swilam
 
Java Script Introduction
jason hu 金良胡
 
Bsc cs i pic u-4 function, storage class and array and strings
Rai University
 
Array-single dimensional array concept .pptx
SindhuVelmukull
 
Ad

More from Vineet Kumar Saini (20)

PDF
Abstract Class and Interface in PHP
Vineet Kumar Saini
 
PDF
Add edit delete in Codeigniter in PHP
Vineet Kumar Saini
 
PDF
Introduction to Html
Vineet Kumar Saini
 
PDF
Computer Fundamentals
Vineet Kumar Saini
 
PDF
Stripe in php
Vineet Kumar Saini
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PDF
Install Drupal on Wamp Server
Vineet Kumar Saini
 
PDF
Joomla 2.5 Tutorial For Beginner PDF
Vineet Kumar Saini
 
PDF
Functions in PHP
Vineet Kumar Saini
 
PDF
Sorting arrays in PHP
Vineet Kumar Saini
 
PDF
Update statement in PHP
Vineet Kumar Saini
 
PDF
Delete statement in PHP
Vineet Kumar Saini
 
PDF
Types of Error in PHP
Vineet Kumar Saini
 
PDF
GET and POST in PHP
Vineet Kumar Saini
 
PDF
Database connectivity in PHP
Vineet Kumar Saini
 
PDF
Arrays in PHP
Vineet Kumar Saini
 
PDF
Programming in C
Vineet Kumar Saini
 
PDF
Browser information in PHP
Vineet Kumar Saini
 
PDF
Operators in PHP
Vineet Kumar Saini
 
PDF
Variables in PHP
Vineet Kumar Saini
 
Abstract Class and Interface in PHP
Vineet Kumar Saini
 
Add edit delete in Codeigniter in PHP
Vineet Kumar Saini
 
Introduction to Html
Vineet Kumar Saini
 
Computer Fundamentals
Vineet Kumar Saini
 
Stripe in php
Vineet Kumar Saini
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Install Drupal on Wamp Server
Vineet Kumar Saini
 
Joomla 2.5 Tutorial For Beginner PDF
Vineet Kumar Saini
 
Functions in PHP
Vineet Kumar Saini
 
Sorting arrays in PHP
Vineet Kumar Saini
 
Update statement in PHP
Vineet Kumar Saini
 
Delete statement in PHP
Vineet Kumar Saini
 
Types of Error in PHP
Vineet Kumar Saini
 
GET and POST in PHP
Vineet Kumar Saini
 
Database connectivity in PHP
Vineet Kumar Saini
 
Arrays in PHP
Vineet Kumar Saini
 
Programming in C
Vineet Kumar Saini
 
Browser information in PHP
Vineet Kumar Saini
 
Operators in PHP
Vineet Kumar Saini
 
Variables in PHP
Vineet Kumar Saini
 
Ad

Recently uploaded (20)

PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
Understanding operators in c language.pptx
auteharshil95
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Understanding operators in c language.pptx
auteharshil95
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Landforms and landscapes data surprise preview
jpinnuck
 
Skill Development Program For Physiotherapy Students by SRY.pptx
Prof.Dr.Y.SHANTHOSHRAJA MPT Orthopedic., MSc Microbiology
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 

Implode & Explode in PHP

  • 1. PHP Tutorials By Vineet Kumar Saini Implode() and Explode() Function in PHP 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) Example1 <html> <body bgcolor="pink"> <h3>Implode Function</h3> <?php $arr=array ('I','am','simple','boy!'); echo implode(" ",$arr); ?> </body> </html> Output
  • 2. PHP Tutorials By Vineet Kumar Saini Example2 <html> <body bgcolor="pink"> <h3>Implode Function</h3> <?php $arr = array ('I','am','simple','boy!'); $space_separated = implode(" ", $arr); $comma_separated = implode(" , ", $arr); $slash_separated = implode(" / ", $arr); $dot_separated = implode(" . ", $arr); $hyphen_separated = implode(" - ", $arr); echo $space_separated.'<br>'; echo $comma_separated.'<br>'; echo $slash_separated.'<br>'; echo $dot_separated.'<br>'; echo $hyphen_separated; ?> </body> </html> Output
  • 3. PHP Tutorials By Vineet Kumar Saini Explode() Function The explode function is used to "Split a string by a specified 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 the explode 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: $arr = Array ("A","E","I","O","U");
  • 4. PHP Tutorials By Vineet Kumar Saini Syntax explode (separator,string,limit) Example1 <html> <body bgcolor="pink"> <h3>Explode Function</h3> <?php $str="I am simple boy!"; print_r(explode(" ",$str)); ?> </body> </html> Output Example2 <html> <body bgcolor="pink"> <h3>Explode Function</h3> <?php $str="I am simple boy!"; print_r(explode("-",$str)); ?> </body> </html>
  • 5. PHP Tutorials By Vineet Kumar Saini Output 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.