Tuesday, January 22, 2008

TIP : Explode and Implode duo function in php



This is duo php function that very useful when we need parser and insert string with any delimiter for example "a-b-c-d-e-f" you can explode to array in php with simple statement

for explode function in php.
-------- PHP Code -------
$str = "a,b,c,d,e,f" ;
$arr = explode(",","a,b,c,d,e,f") ; //This function will extract by "," and add for each character to array
print_r($arr);
---------------------------
Output:
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
)




for implode function in php .
-------- PHP Code -------
$arr = array('a','b','c','d','e','f');
$str = implode('-',$arr); //this function will insert '-' character between array element
print_r($str);
---------------------------
Output:
a-b-c-d-e-f

Note :
implode and explode in php5 are useful when you manipulate with CSV file with any delimiter for example white space, comma, colon .

Today's Joke :
Remember that explode is a bomb also implode is a glue.


Add to: Power Oldie Add to: Digg Add to: Del.icio.us Add to: StumbleUpon Add to: Yahoo Add to: Spurl Add to: Google

4 comments:

PHP Training Kolkata said...

It's Fantastic php related blog. I liked it.
PHP Training

upgrade sap 6.0 said...

What a great explanation about this function. I am messing up on the internet to find some info about this function and finally found it on your blog post. Thank you so much for explaining it so nicely and sharing the example to show the execution.

Anonymous said...

Acesoftech is kolkata’s top PHP training center where professional php training is provided. The training is provided by not by the faculties but professionals who have already worked in this field. PHP is in demand, does that mean that its very easy to find job. And if its like that why there are hundreds of students how are jobless in spite of having knowledge of PHP? The reason is simple, they know php but they does not know it professionally. They have not been trained in proper way .
Acesoftech trains in such a way that you can get job instantly because we trains the things which are in demand in the industry.
If you are looking for professional PHP training in Kolkata, acesoftech guarantee you of building your career in PHP.

Neeraj Maheshwari said...

hi all,
i m using xampp (1.8.3) and oracle 9 (ora92).
when i enable oci8 extension it gives error -

PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\php_oci8.dll

please help me out.