breaking up 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
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

breaking up a string

Post by speedy33417 »

What is the best way to break up a string separated by a certain character. I have path saved in $path which could me something like this:
folder1/folder2/folder3/

I'd like to break up the string into
folder1
folder2
folder3

and save it into an array.

Any suggestions would be great.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post by speedy33417 »

Cheers. Exactly what I was looking for.
User avatar
speedy33417
Forum Contributor
Posts: 128
Joined: Sun Jul 23, 2006 1:14 pm

Post by speedy33417 »

Exploding my string will give me unpredictable amount of pieces. How do I find out how many pieces I got?

Code: Select all

$pieces = explode("/", $path);
Thanks.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Try

Code: Select all

count()
Post Reply