OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :
 

Explode

By admin (2004-12-17. 7149 views.)
A description of how the PHP explode statement works.

Explode takes a string and splits it up. You can split a string into an array as follows:


<?php

$mystring 
"Fred,Bloggs,10 Fred's Road,Fredsville";
$myarray explode(',' $mystring);

?>


What the above does is it splits the string wherever a ',' is found, so the resultant array would be as follows:

$myarray[0] = "Fred"
$myarray[1] = "Bloggs"
$myarray[2] = "10 Fred's Road"
$myarray[3] = "Fredsville"

You could also split it into a list of variables as follows:


<?php

$mystring1 
"Fred|Bloggs|10 Fred's Road|Fredsville";
list(
$first$last$road$town) = explode('|' $mystring1);

?>


Which would give:

$first = "Fred"
$last = "Bloggs"
$road = "10 Fred's Road"
$town = "Fredsville"

You can reverse the effects of explode with implode. Working with the array of:

$myarray[0] = "Fred"
$myarray[1] = "Bloggs"
$myarray[2] = "10 Fred's Road"
$myarray[3] = "Fredsville"

We could put it back together with:


<?php

$mystring 
implode(','$myarray);

?>


And $mystring would once again be: "Fred,Bloggs,10 Fred's Road,Fredsville"



Be careful exploding an empty string as it will still create an array with a blank member. For example:


<?php

$mystring 
"";
$myarray explode(',' $mystring);

?>


Would still define:

$myarray[0] = ""

This may be of some consequence if you use the array at some point later.
 

 
   Print this page

Top Sponsor
Symantec\'s Norton SystemWorks 2006
Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting

Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005