explode a string

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
dheeraj
Forum Commoner
Posts: 40
Joined: Fri Feb 06, 2009 11:54 am

explode a string

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: explode a string

Post by requinix »

Try str_split instead.
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: explode a string

Post 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);
 
Post Reply