Breaking down variables

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
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Breaking down variables

Post 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....!
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Check out the substr() fn.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I suspect this question doesn't belong in the advanced forum.. anyway, check out the substr() fn.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Nunners
Forum Commoner
Posts: 89
Joined: Tue Jan 28, 2003 7:52 am
Location: Worcester, UK
Contact:

Post by Nunners »

Sorry for putting it in the wrong forum....

the substr() has worked perfectly....

Thanks once again guys....
Post Reply