Page 1 of 1

Breaking down variables

Posted: Tue Jun 17, 2003 8:18 am
by Nunners
There is probably a really simple way to do this, but I can't find it in the list of functions in PHP....

I've got a variable e.g. SO7567 and I want to break it down in three parts: SO, 75, 67 and then carry out actions on each part....

Is there an easy way of doing this? In fact, is there a way in PHP?

The variable in this case is always 6 chars long, and I always want it split into 3.

For those interested, SO7567 is a GB mapping reference, and I want to turn it into a true reference - which I can do....!

Posted: Tue Jun 17, 2003 8:27 am
by releasedj
If this is an array then just loop through using a foreach statement and check the name of the key.

I expect, however, that you're talking about global variables, if so you can use the get_defined_vars() function which will return an associative array of all defined variables. You can then simply loop through each value.

Kelvin

Posted: Tue Jun 17, 2003 8:40 am
by McGruff
Check out the substr() fn.

Posted: Tue Jun 17, 2003 8:42 am
by McGruff
I suspect this question doesn't belong in the advanced forum.. anyway, check out the substr() fn.

Posted: Tue Jun 17, 2003 9:25 am
by twigletmac
McGruff wrote:I suspect this question doesn't belong in the advanced forum..
Yup, you're right. This is a 'how to' question and thus belongs in PHP - Normal not in Advanced.

Mac

Posted: Tue Jun 17, 2003 10:13 am
by Nunners
Sorry for putting it in the wrong forum....

the substr() has worked perfectly....

Thanks once again guys....