Retrieving values from 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
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Retrieving values from a string

Post by aceconcepts »

Hi,

I have a string that contains values seperated by commas.

I don't know how many values will be in the string at any one time.

I want to be able to extract each value individually so that I can do something with them.

A text field will be used inside of a form to retrieve the input values. I am keen to use an array I'm just a little bit rusty with string manipulation.

How would one go about doing this?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

From what I understand you have two choices... explode as you know you are separating by commas (If you can guarantee text does not have "textbock","text,block") or preg_match if it does (you'll have to work out the pattern to match your specific possibilities). In general I think explode will suffice. You then use the array created to do as you wish..
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Excellent. Thanks.
Post Reply