Wednesday, 6 February 2013

PHP Implode and PHP Explode Function | PHP Tutorial for Beginners


In this tutorial of php code for beginners we will see how to use php explode and implode function.

PHP explode() Function:-
Php explode function is used to break a string into an array. We specify the parameter which is used in breaking the string.

Syntax of explode function is as follow:- 
explode(Separator,String)
where 'Separator' specify the position from where to break string and 'String' is actual text which will split.

Here is the example to show php explode function.
<?php
$string = "PHP tutorial to use explode and implode functions for beginners.";
$data = explode(" ", $string);
foreach($data as $parts) {
echo $parts . "<br/>";
}
?>
Output:-
PHP
tutorial
to
use
explode
and
implode
functions
for
beginners.


PHP implode() Function:-
Php implode function is used to convert an array into string. It return output as a string.

Syntax of implode function is as follow:- 
implode(Separator,Array)
where 'Separator' indicate what to be come in between array elements and 'Array' is one which will get converted into string.

Here is the two examples to show php implode function.
<?php
$string = array("PHP","tutorial","to","use","explode","and","implode","functions","for","beginners.");
$data = implode(" ", $string);
echo $data;
?>
Output:-
PHP tutorial to use explode and implode functions for beginners.

<?php
$string = array("PHP","tutorial","to","use","explode","and","implode","functions","for","beginners.");
$data = implode("-", $string);
echo $data;
?>
Output:-
PHP-tutorial-to-use-explode-and-implode-functions-for-beginners.

Hope this php tutorial is useful for you. Keep following www.phpcodeforbeginner.blogspot.in for more help.

No comments:

Post a Comment