Blog Details

explode and implode function



                                

* PHP  explode() Function :

  • The explode() function breaks a string into an array.
 

Syntax :

explode(separator,string,limit)

Example :

<html> <body> <?php $str = "Hello world. It's a beautiful day."; print_r (explode(" ",$str)); ?> </body> </html>

Output :

Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )

* PHP implode() Function :-

  • The implode() function returns a string from the elements of an array.
  • Join array elements with a string:
 

Syntax :

implode(separator,array)

Example :

<html> <body> <?php $arr = array('Hello','World!','Beautiful','Day!'); echo implode(" ",$arr)."<br>"; echo implode("+",$arr)."<br>"; echo implode("-",$arr)."<br>"; echo implode("X",$arr); ?> </body> </html>

Output :

Hello World! Beautiful Day! Hello+World!+Beautiful+Day! Hello-World!-Beautiful-Day! HelloXWorld!XBeautifulXDay!


Categories

Core_PHP

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote