explode help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

explode help

Post by elecktricity »

how would I explode a variable by characters like:

Code: Select all

<?PHP
$variable = 'hello all';
/* explode
$var = explode('', $variable);
*/
$var[0] = 'h';
$var[1] = 'e';
$var[2] = 'l';
$var[3] = 'l';
$var[4] = 'o';
$var[5] = ' ';
$var[6] = 'a';
$var[7] = 'l';
$var[8] = 'l';
?>
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

str_split() seems to be what you need.
User avatar
themurph
Forum Commoner
Posts: 76
Joined: Wed Apr 19, 2006 1:56 pm
Contact:

Post by themurph »

You wouldnt want to use explode to do that.. explode is usually used to parse values stored with a specific character as a delimiter like "\t" ot "," or "|"

Mabye try something like this instead:

Code: Select all

$variable = 'hello all'; 
$var= array();
for ($x=0; $x < $strlen($variable); $x++) { $var[$x] = $variable[$x]; }
User avatar
themurph
Forum Commoner
Posts: 76
Joined: Wed Apr 19, 2006 1:56 pm
Contact:

Post by themurph »

scratch that... wasn't even aware of str_split
Post Reply