Page 1 of 1

explode a string

Posted: Fri Feb 06, 2009 10:43 pm
by dheeraj
I want to explode a string into an array where all of the letters are a value to the array...

Let's say I have the following string for example...

$str = "abs12fg";

I want that to become equivalent to

array('a', 'b', 's', '1', '2', 'f', 'g');

I've tried explode('', $str); & split()lbut that doesn't help... thanks.

Re: explode a string

Posted: Fri Feb 06, 2009 11:08 pm
by requinix
Try str_split instead.

Re: explode a string

Posted: Sat Feb 07, 2009 9:33 am
by Skoalbasher
dheeraj wrote:I want to explode a string into an array where all of the letters are a value to the array...

Let's say I have the following string for example...

$str = "abs12fg";

I want that to become equivalent to

array('a', 'b', 's', '1', '2', 'f', 'g');

I've tried explode('', $str); & split()lbut that doesn't help... thanks.
I'm pretty sure explode doesn't work like that. Explode needs something to seperate.

Code: Select all

 
$str = "a,b,c,d,e,f,g";
 
$strex = explode(",", $str);
 
print_r($strex);