Help with manipulating 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
michael_mead
Forum Newbie
Posts: 2
Joined: Sun Dec 14, 2003 4:37 pm

Help with manipulating a string.

Post by michael_mead »

Hi,

I have a string that looks like this;

example:example:example

It consists of three words, each seperated by colons and are of variable length.

I want to get these words from the string and put them into a variable.

Using php.net I can see a way to do it, but it looks very complicated and there must be an easier way that I have overlooked.

If someone could help me that would be great.

Thanks

Mike
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

You can explode() them:

$mystring = "example:example:example";
$mywords = explode(":", $mystring);

Now an array called $mywords will exist that contains each of the words in $mystring.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

More info and examples:

explode()
michael_mead
Forum Newbie
Posts: 2
Joined: Sun Dec 14, 2003 4:37 pm

Post by michael_mead »

Hi,

Thats fantastic, when I am on my computer this evening, I will use that.

Thanks for your help, I dont know how I overlooked that.

Regards

Mike
Post Reply